ADAPT-Chase commited on
Commit
5d7a119
·
verified ·
1 Parent(s): 7f300d1

Add files using upload-large-folder tool

Browse files
This view is limited to 50 files because it contains too many changes.   See raw diff
Files changed (50) hide show
  1. platform/aiml/elizabeth/e-1-first_session/claude-code-router/node_modules/ajv/dist/vocabularies/validation/pattern.js +24 -0
  2. platform/aiml/elizabeth/e-1-first_session/claude-code-router/node_modules/ajv/dist/vocabularies/validation/required.js.map +1 -0
  3. platform/aiml/elizabeth/e-1-first_session/claude-code-router/node_modules/ajv/dist/vocabularies/validation/uniqueItems.d.ts +9 -0
  4. platform/aiml/elizabeth/e-1-first_session/claude-code-router/node_modules/ajv/lib/compile/codegen/code.ts +169 -0
  5. platform/aiml/elizabeth/e-1-first_session/claude-code-router/node_modules/ajv/lib/compile/codegen/index.ts +852 -0
  6. platform/aiml/elizabeth/e-1-first_session/claude-code-router/node_modules/ajv/lib/compile/codegen/scope.ts +215 -0
  7. platform/aiml/elizabeth/e-1-first_session/claude-code-router/node_modules/ajv/lib/compile/errors.ts +184 -0
  8. platform/aiml/elizabeth/e-1-first_session/claude-code-router/node_modules/ajv/lib/compile/index.ts +324 -0
  9. platform/aiml/elizabeth/e-1-first_session/claude-code-router/node_modules/ajv/lib/compile/jtd/parse.ts +411 -0
  10. platform/aiml/elizabeth/e-1-first_session/claude-code-router/node_modules/ajv/lib/compile/jtd/serialize.ts +266 -0
  11. platform/aiml/elizabeth/e-1-first_session/claude-code-router/node_modules/ajv/lib/compile/jtd/types.ts +16 -0
  12. platform/aiml/elizabeth/e-1-first_session/claude-code-router/node_modules/ajv/lib/compile/ref_error.ts +13 -0
  13. platform/aiml/elizabeth/e-1-first_session/claude-code-router/node_modules/ajv/lib/compile/resolve.ts +149 -0
  14. platform/aiml/elizabeth/e-1-first_session/claude-code-router/node_modules/ajv/lib/compile/validate/applicability.ts +22 -0
  15. platform/aiml/elizabeth/e-1-first_session/claude-code-router/node_modules/ajv/lib/compile/validate/boolSchema.ts +47 -0
  16. platform/aiml/elizabeth/e-1-first_session/claude-code-router/node_modules/ajv/lib/compile/validate/dataType.ts +230 -0
  17. platform/aiml/elizabeth/e-1-first_session/claude-code-router/node_modules/ajv/lib/compile/validate/defaults.ts +32 -0
  18. platform/aiml/elizabeth/e-1-first_session/claude-code-router/node_modules/ajv/lib/compile/validate/index.ts +582 -0
  19. platform/aiml/elizabeth/e-1-first_session/claude-code-router/node_modules/ajv/lib/compile/validate/keyword.ts +171 -0
  20. platform/aiml/elizabeth/e-1-first_session/claude-code-router/node_modules/ajv/lib/compile/validate/subschema.ts +135 -0
  21. platform/aiml/elizabeth/e-1-first_session/claude-code-router/node_modules/ajv/lib/refs/data.json +13 -0
  22. platform/aiml/elizabeth/e-1-first_session/claude-code-router/node_modules/ajv/lib/refs/json-schema-2019-09/index.ts +28 -0
  23. platform/aiml/elizabeth/e-1-first_session/claude-code-router/node_modules/ajv/lib/refs/json-schema-2019-09/meta/applicator.json +53 -0
  24. platform/aiml/elizabeth/e-1-first_session/claude-code-router/node_modules/ajv/lib/refs/json-schema-2019-09/meta/content.json +17 -0
  25. platform/aiml/elizabeth/e-1-first_session/claude-code-router/node_modules/ajv/lib/refs/json-schema-2019-09/meta/core.json +57 -0
  26. platform/aiml/elizabeth/e-1-first_session/claude-code-router/node_modules/ajv/lib/refs/json-schema-2019-09/meta/format.json +14 -0
  27. platform/aiml/elizabeth/e-1-first_session/claude-code-router/node_modules/ajv/lib/refs/json-schema-2019-09/meta/meta-data.json +37 -0
  28. platform/aiml/elizabeth/e-1-first_session/claude-code-router/node_modules/ajv/lib/refs/json-schema-2019-09/meta/validation.json +90 -0
  29. platform/aiml/elizabeth/e-1-first_session/claude-code-router/node_modules/ajv/lib/refs/json-schema-2019-09/schema.json +39 -0
  30. platform/aiml/elizabeth/e-1-first_session/claude-code-router/node_modules/ajv/lib/refs/json-schema-2020-12/index.ts +30 -0
  31. platform/aiml/elizabeth/e-1-first_session/claude-code-router/node_modules/ajv/lib/refs/json-schema-2020-12/meta/applicator.json +48 -0
  32. platform/aiml/elizabeth/e-1-first_session/claude-code-router/node_modules/ajv/lib/refs/json-schema-2020-12/meta/content.json +17 -0
  33. platform/aiml/elizabeth/e-1-first_session/claude-code-router/node_modules/ajv/lib/refs/json-schema-2020-12/meta/core.json +51 -0
  34. platform/aiml/elizabeth/e-1-first_session/claude-code-router/node_modules/ajv/lib/refs/json-schema-2020-12/meta/format-annotation.json +14 -0
  35. platform/aiml/elizabeth/e-1-first_session/claude-code-router/node_modules/ajv/lib/refs/json-schema-2020-12/meta/meta-data.json +37 -0
  36. platform/aiml/elizabeth/e-1-first_session/claude-code-router/node_modules/ajv/lib/refs/json-schema-2020-12/meta/unevaluated.json +15 -0
  37. platform/aiml/elizabeth/e-1-first_session/claude-code-router/node_modules/ajv/lib/refs/json-schema-2020-12/meta/validation.json +90 -0
  38. platform/aiml/elizabeth/e-1-first_session/claude-code-router/node_modules/ajv/lib/refs/json-schema-2020-12/schema.json +55 -0
  39. platform/aiml/elizabeth/e-1-first_session/claude-code-router/node_modules/ajv/lib/refs/json-schema-draft-06.json +137 -0
  40. platform/aiml/elizabeth/e-1-first_session/claude-code-router/node_modules/ajv/lib/refs/json-schema-draft-07.json +151 -0
  41. platform/aiml/elizabeth/e-1-first_session/claude-code-router/node_modules/ajv/lib/refs/json-schema-secure.json +88 -0
  42. platform/aiml/elizabeth/e-1-first_session/claude-code-router/node_modules/ajv/lib/refs/jtd-schema.ts +130 -0
  43. platform/aiml/elizabeth/e-1-first_session/claude-code-router/node_modules/ajv/lib/runtime/equal.ts +7 -0
  44. platform/aiml/elizabeth/e-1-first_session/claude-code-router/node_modules/ajv/lib/runtime/parseJson.ts +177 -0
  45. platform/aiml/elizabeth/e-1-first_session/claude-code-router/node_modules/ajv/lib/runtime/quote.ts +31 -0
  46. platform/aiml/elizabeth/e-1-first_session/claude-code-router/node_modules/ajv/lib/runtime/re2.ts +6 -0
  47. platform/aiml/elizabeth/e-1-first_session/claude-code-router/node_modules/ajv/lib/runtime/timestamp.ts +46 -0
  48. platform/aiml/elizabeth/e-1-first_session/claude-code-router/node_modules/ajv/lib/runtime/ucs2length.ts +20 -0
  49. platform/aiml/elizabeth/e-1-first_session/claude-code-router/node_modules/ajv/lib/runtime/uri.ts +6 -0
  50. platform/aiml/elizabeth/e-1-first_session/claude-code-router/node_modules/ajv/lib/runtime/validation_error.ts +13 -0
platform/aiml/elizabeth/e-1-first_session/claude-code-router/node_modules/ajv/dist/vocabularies/validation/pattern.js ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const code_1 = require("../code");
4
+ const codegen_1 = require("../../compile/codegen");
5
+ const error = {
6
+ message: ({ schemaCode }) => (0, codegen_1.str) `must match pattern "${schemaCode}"`,
7
+ params: ({ schemaCode }) => (0, codegen_1._) `{pattern: ${schemaCode}}`,
8
+ };
9
+ const def = {
10
+ keyword: "pattern",
11
+ type: "string",
12
+ schemaType: "string",
13
+ $data: true,
14
+ error,
15
+ code(cxt) {
16
+ const { data, $data, schema, schemaCode, it } = cxt;
17
+ // TODO regexp should be wrapped in try/catchs
18
+ const u = it.opts.unicodeRegExp ? "u" : "";
19
+ const regExp = $data ? (0, codegen_1._) `(new RegExp(${schemaCode}, ${u}))` : (0, code_1.usePattern)(cxt, schema);
20
+ cxt.fail$data((0, codegen_1._) `!${regExp}.test(${data})`);
21
+ },
22
+ };
23
+ exports.default = def;
24
+ //# sourceMappingURL=pattern.js.map
platform/aiml/elizabeth/e-1-first_session/claude-code-router/node_modules/ajv/dist/vocabularies/validation/required.js.map ADDED
@@ -0,0 +1 @@
 
 
1
+ {"version":3,"file":"required.js","sourceRoot":"","sources":["../../../lib/vocabularies/validation/required.ts"],"names":[],"mappings":";;AAEA,kCAMgB;AAChB,mDAAkE;AAClE,6CAAkD;AAQlD,MAAM,KAAK,GAA2B;IACpC,OAAO,EAAE,CAAC,EAAC,MAAM,EAAE,EAAC,eAAe,EAAC,EAAC,EAAE,EAAE,CAAC,IAAA,aAAG,EAAA,gCAAgC,eAAe,GAAG;IAC/F,MAAM,EAAE,CAAC,EAAC,MAAM,EAAE,EAAC,eAAe,EAAC,EAAC,EAAE,EAAE,CAAC,IAAA,WAAC,EAAA,qBAAqB,eAAe,GAAG;CAClF,CAAA;AAED,MAAM,GAAG,GAA0B;IACjC,OAAO,EAAE,UAAU;IACnB,IAAI,EAAE,QAAQ;IACd,UAAU,EAAE,OAAO;IACnB,KAAK,EAAE,IAAI;IACX,KAAK;IACL,IAAI,CAAC,GAAe;QAClB,MAAM,EAAC,GAAG,EAAE,MAAM,EAAE,UAAU,EAAE,IAAI,EAAE,KAAK,EAAE,EAAE,EAAC,GAAG,GAAG,CAAA;QACtD,MAAM,EAAC,IAAI,EAAC,GAAG,EAAE,CAAA;QACjB,IAAI,CAAC,KAAK,IAAI,MAAM,CAAC,MAAM,KAAK,CAAC;YAAE,OAAM;QACzC,MAAM,OAAO,GAAG,MAAM,CAAC,MAAM,IAAI,IAAI,CAAC,YAAY,CAAA;QAClD,IAAI,EAAE,CAAC,SAAS;YAAE,aAAa,EAAE,CAAA;;YAC5B,eAAe,EAAE,CAAA;QAEtB,IAAI,IAAI,CAAC,cAAc,EAAE,CAAC;YACxB,MAAM,KAAK,GAAG,GAAG,CAAC,YAAY,CAAC,UAAU,CAAA;YACzC,MAAM,EAAC,iBAAiB,EAAC,GAAG,GAAG,CAAC,EAAE,CAAA;YAClC,KAAK,MAAM,WAAW,IAAI,MAAM,EAAE,CAAC;gBACjC,IAAI,CAAA,KAAK,aAAL,KAAK,uBAAL,KAAK,CAAG,WAAW,CAAC,MAAK,SAAS,IAAI,CAAC,iBAAiB,CAAC,GAAG,CAAC,WAAW,CAAC,EAAE,CAAC;oBAC9E,MAAM,UAAU,GAAG,EAAE,CAAC,SAAS,CAAC,MAAM,GAAG,EAAE,CAAC,aAAa,CAAA;oBACzD,MAAM,GAAG,GAAG,sBAAsB,WAAW,wBAAwB,UAAU,oBAAoB,CAAA;oBACnG,IAAA,sBAAe,EAAC,EAAE,EAAE,GAAG,EAAE,EAAE,CAAC,IAAI,CAAC,cAAc,CAAC,CAAA;gBAClD,CAAC;YACH,CAAC;QACH,CAAC;QAED,SAAS,aAAa;YACpB,IAAI,OAAO,IAAI,KAAK,EAAE,CAAC;gBACrB,GAAG,CAAC,UAAU,CAAC,aAAG,EAAE,eAAe,CAAC,CAAA;YACtC,CAAC;iBAAM,CAAC;gBACN,KAAK,MAAM,IAAI,IAAI,MAAM,EAAE,CAAC;oBAC1B,IAAA,6BAAsB,EAAC,GAAG,EAAE,IAAI,CAAC,CAAA;gBACnC,CAAC;YACH,CAAC;QACH,CAAC;QAED,SAAS,eAAe;YACtB,MAAM,OAAO,GAAG,GAAG,CAAC,GAAG,CAAC,SAAS,CAAC,CAAA;YAClC,IAAI,OAAO,IAAI,KAAK,EAAE,CAAC;gBACrB,MAAM,KAAK,GAAG,GAAG,CAAC,GAAG,CAAC,OAAO,EAAE,IAAI,CAAC,CAAA;gBACpC,GAAG,CAAC,UAAU,CAAC,KAAK,EAAE,GAAG,EAAE,CAAC,gBAAgB,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC,CAAA;gBAC7D,GAAG,CAAC,EAAE,CAAC,KAAK,CAAC,CAAA;YACf,CAAC;iBAAM,CAAC;gBACN,GAAG,CAAC,EAAE,CAAC,IAAA,uBAAgB,EAAC,GAAG,EAAE,MAAM,EAAE,OAAO,CAAC,CAAC,CAAA;gBAC9C,IAAA,wBAAiB,EAAC,GAAG,EAAE,OAAO,CAAC,CAAA;gBAC/B,GAAG,CAAC,IAAI,EAAE,CAAA;YACZ,CAAC;QACH,CAAC;QAED,SAAS,eAAe;YACtB,GAAG,CAAC,KAAK,CAAC,MAAM,EAAE,UAAkB,EAAE,CAAC,IAAI,EAAE,EAAE;gBAC7C,GAAG,CAAC,SAAS,CAAC,EAAC,eAAe,EAAE,IAAI,EAAC,CAAC,CAAA;gBACtC,GAAG,CAAC,EAAE,CAAC,IAAA,uBAAgB,EAAC,GAAG,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,CAAC,aAAa,CAAC,EAAE,GAAG,EAAE,CAAC,GAAG,CAAC,KAAK,EAAE,CAAC,CAAA;YAClF,CAAC,CAAC,CAAA;QACJ,CAAC;QAED,SAAS,gBAAgB,CAAC,OAAa,EAAE,KAAW;YAClD,GAAG,CAAC,SAAS,CAAC,EAAC,eAAe,EAAE,OAAO,EAAC,CAAC,CAAA;YACzC,GAAG,CAAC,KAAK,CACP,OAAO,EACP,UAAkB,EAClB,GAAG,EAAE;gBACH,GAAG,CAAC,MAAM,CAAC,KAAK,EAAE,IAAA,qBAAc,EAAC,GAAG,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,CAAC,aAAa,CAAC,CAAC,CAAA;gBACzE,GAAG,CAAC,EAAE,CAAC,IAAA,aAAG,EAAC,KAAK,CAAC,EAAE,GAAG,EAAE;oBACtB,GAAG,CAAC,KAAK,EAAE,CAAA;oBACX,GAAG,CAAC,KAAK,EAAE,CAAA;gBACb,CAAC,CAAC,CAAA;YACJ,CAAC,EACD,aAAG,CACJ,CAAA;QACH,CAAC;IACH,CAAC;CACF,CAAA;AAED,kBAAe,GAAG,CAAA"}
platform/aiml/elizabeth/e-1-first_session/claude-code-router/node_modules/ajv/dist/vocabularies/validation/uniqueItems.d.ts ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
 
1
+ import type { CodeKeywordDefinition, ErrorObject } from "../../types";
2
+ export type UniqueItemsError = ErrorObject<"uniqueItems", {
3
+ i: number;
4
+ j: number;
5
+ }, boolean | {
6
+ $data: string;
7
+ }>;
8
+ declare const def: CodeKeywordDefinition;
9
+ export default def;
platform/aiml/elizabeth/e-1-first_session/claude-code-router/node_modules/ajv/lib/compile/codegen/code.ts ADDED
@@ -0,0 +1,169 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // eslint-disable-next-line @typescript-eslint/no-extraneous-class
2
+ export abstract class _CodeOrName {
3
+ abstract readonly str: string
4
+ abstract readonly names: UsedNames
5
+ abstract toString(): string
6
+ abstract emptyStr(): boolean
7
+ }
8
+
9
+ export const IDENTIFIER = /^[a-z$_][a-z$_0-9]*$/i
10
+
11
+ export class Name extends _CodeOrName {
12
+ readonly str: string
13
+ constructor(s: string) {
14
+ super()
15
+ if (!IDENTIFIER.test(s)) throw new Error("CodeGen: name must be a valid identifier")
16
+ this.str = s
17
+ }
18
+
19
+ toString(): string {
20
+ return this.str
21
+ }
22
+
23
+ emptyStr(): boolean {
24
+ return false
25
+ }
26
+
27
+ get names(): UsedNames {
28
+ return {[this.str]: 1}
29
+ }
30
+ }
31
+
32
+ export class _Code extends _CodeOrName {
33
+ readonly _items: readonly CodeItem[]
34
+ private _str?: string
35
+ private _names?: UsedNames
36
+
37
+ constructor(code: string | readonly CodeItem[]) {
38
+ super()
39
+ this._items = typeof code === "string" ? [code] : code
40
+ }
41
+
42
+ toString(): string {
43
+ return this.str
44
+ }
45
+
46
+ emptyStr(): boolean {
47
+ if (this._items.length > 1) return false
48
+ const item = this._items[0]
49
+ return item === "" || item === '""'
50
+ }
51
+
52
+ get str(): string {
53
+ return (this._str ??= this._items.reduce((s: string, c: CodeItem) => `${s}${c}`, ""))
54
+ }
55
+
56
+ get names(): UsedNames {
57
+ return (this._names ??= this._items.reduce((names: UsedNames, c) => {
58
+ if (c instanceof Name) names[c.str] = (names[c.str] || 0) + 1
59
+ return names
60
+ }, {}))
61
+ }
62
+ }
63
+
64
+ export type CodeItem = Name | string | number | boolean | null
65
+
66
+ export type UsedNames = Record<string, number | undefined>
67
+
68
+ export type Code = _Code | Name
69
+
70
+ export type SafeExpr = Code | number | boolean | null
71
+
72
+ export const nil = new _Code("")
73
+
74
+ type CodeArg = SafeExpr | string | undefined
75
+
76
+ export function _(strs: TemplateStringsArray, ...args: CodeArg[]): _Code {
77
+ const code: CodeItem[] = [strs[0]]
78
+ let i = 0
79
+ while (i < args.length) {
80
+ addCodeArg(code, args[i])
81
+ code.push(strs[++i])
82
+ }
83
+ return new _Code(code)
84
+ }
85
+
86
+ const plus = new _Code("+")
87
+
88
+ export function str(strs: TemplateStringsArray, ...args: (CodeArg | string[])[]): _Code {
89
+ const expr: CodeItem[] = [safeStringify(strs[0])]
90
+ let i = 0
91
+ while (i < args.length) {
92
+ expr.push(plus)
93
+ addCodeArg(expr, args[i])
94
+ expr.push(plus, safeStringify(strs[++i]))
95
+ }
96
+ optimize(expr)
97
+ return new _Code(expr)
98
+ }
99
+
100
+ export function addCodeArg(code: CodeItem[], arg: CodeArg | string[]): void {
101
+ if (arg instanceof _Code) code.push(...arg._items)
102
+ else if (arg instanceof Name) code.push(arg)
103
+ else code.push(interpolate(arg))
104
+ }
105
+
106
+ function optimize(expr: CodeItem[]): void {
107
+ let i = 1
108
+ while (i < expr.length - 1) {
109
+ if (expr[i] === plus) {
110
+ const res = mergeExprItems(expr[i - 1], expr[i + 1])
111
+ if (res !== undefined) {
112
+ expr.splice(i - 1, 3, res)
113
+ continue
114
+ }
115
+ expr[i++] = "+"
116
+ }
117
+ i++
118
+ }
119
+ }
120
+
121
+ function mergeExprItems(a: CodeItem, b: CodeItem): CodeItem | undefined {
122
+ if (b === '""') return a
123
+ if (a === '""') return b
124
+ if (typeof a == "string") {
125
+ if (b instanceof Name || a[a.length - 1] !== '"') return
126
+ if (typeof b != "string") return `${a.slice(0, -1)}${b}"`
127
+ if (b[0] === '"') return a.slice(0, -1) + b.slice(1)
128
+ return
129
+ }
130
+ if (typeof b == "string" && b[0] === '"' && !(a instanceof Name)) return `"${a}${b.slice(1)}`
131
+ return
132
+ }
133
+
134
+ export function strConcat(c1: Code, c2: Code): Code {
135
+ return c2.emptyStr() ? c1 : c1.emptyStr() ? c2 : str`${c1}${c2}`
136
+ }
137
+
138
+ // TODO do not allow arrays here
139
+ function interpolate(x?: string | string[] | number | boolean | null): SafeExpr | string {
140
+ return typeof x == "number" || typeof x == "boolean" || x === null
141
+ ? x
142
+ : safeStringify(Array.isArray(x) ? x.join(",") : x)
143
+ }
144
+
145
+ export function stringify(x: unknown): Code {
146
+ return new _Code(safeStringify(x))
147
+ }
148
+
149
+ export function safeStringify(x: unknown): string {
150
+ return JSON.stringify(x)
151
+ .replace(/\u2028/g, "\\u2028")
152
+ .replace(/\u2029/g, "\\u2029")
153
+ }
154
+
155
+ export function getProperty(key: Code | string | number): Code {
156
+ return typeof key == "string" && IDENTIFIER.test(key) ? new _Code(`.${key}`) : _`[${key}]`
157
+ }
158
+
159
+ //Does best effort to format the name properly
160
+ export function getEsmExportName(key: Code | string | number): Code {
161
+ if (typeof key == "string" && IDENTIFIER.test(key)) {
162
+ return new _Code(`${key}`)
163
+ }
164
+ throw new Error(`CodeGen: invalid export name: ${key}, use explicit $id name mapping`)
165
+ }
166
+
167
+ export function regexpCode(rx: RegExp): Code {
168
+ return new _Code(rx.toString())
169
+ }
platform/aiml/elizabeth/e-1-first_session/claude-code-router/node_modules/ajv/lib/compile/codegen/index.ts ADDED
@@ -0,0 +1,852 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import type {ScopeValueSets, NameValue, ValueScope, ValueScopeName} from "./scope"
2
+ import {_, nil, _Code, Code, Name, UsedNames, CodeItem, addCodeArg, _CodeOrName} from "./code"
3
+ import {Scope, varKinds} from "./scope"
4
+
5
+ export {_, str, strConcat, nil, getProperty, stringify, regexpCode, Name, Code} from "./code"
6
+ export {Scope, ScopeStore, ValueScope, ValueScopeName, ScopeValueSets, varKinds} from "./scope"
7
+
8
+ // type for expressions that can be safely inserted in code without quotes
9
+ export type SafeExpr = Code | number | boolean | null
10
+
11
+ // type that is either Code of function that adds code to CodeGen instance using its methods
12
+ export type Block = Code | (() => void)
13
+
14
+ export const operators = {
15
+ GT: new _Code(">"),
16
+ GTE: new _Code(">="),
17
+ LT: new _Code("<"),
18
+ LTE: new _Code("<="),
19
+ EQ: new _Code("==="),
20
+ NEQ: new _Code("!=="),
21
+ NOT: new _Code("!"),
22
+ OR: new _Code("||"),
23
+ AND: new _Code("&&"),
24
+ ADD: new _Code("+"),
25
+ }
26
+
27
+ abstract class Node {
28
+ abstract readonly names: UsedNames
29
+
30
+ optimizeNodes(): this | ChildNode | ChildNode[] | undefined {
31
+ return this
32
+ }
33
+
34
+ optimizeNames(_names: UsedNames, _constants: Constants): this | undefined {
35
+ return this
36
+ }
37
+
38
+ // get count(): number {
39
+ // return 1
40
+ // }
41
+ }
42
+
43
+ class Def extends Node {
44
+ constructor(
45
+ private readonly varKind: Name,
46
+ private readonly name: Name,
47
+ private rhs?: SafeExpr
48
+ ) {
49
+ super()
50
+ }
51
+
52
+ render({es5, _n}: CGOptions): string {
53
+ const varKind = es5 ? varKinds.var : this.varKind
54
+ const rhs = this.rhs === undefined ? "" : ` = ${this.rhs}`
55
+ return `${varKind} ${this.name}${rhs};` + _n
56
+ }
57
+
58
+ optimizeNames(names: UsedNames, constants: Constants): this | undefined {
59
+ if (!names[this.name.str]) return
60
+ if (this.rhs) this.rhs = optimizeExpr(this.rhs, names, constants)
61
+ return this
62
+ }
63
+
64
+ get names(): UsedNames {
65
+ return this.rhs instanceof _CodeOrName ? this.rhs.names : {}
66
+ }
67
+ }
68
+
69
+ class Assign extends Node {
70
+ constructor(
71
+ readonly lhs: Code,
72
+ public rhs: SafeExpr,
73
+ private readonly sideEffects?: boolean
74
+ ) {
75
+ super()
76
+ }
77
+
78
+ render({_n}: CGOptions): string {
79
+ return `${this.lhs} = ${this.rhs};` + _n
80
+ }
81
+
82
+ optimizeNames(names: UsedNames, constants: Constants): this | undefined {
83
+ if (this.lhs instanceof Name && !names[this.lhs.str] && !this.sideEffects) return
84
+ this.rhs = optimizeExpr(this.rhs, names, constants)
85
+ return this
86
+ }
87
+
88
+ get names(): UsedNames {
89
+ const names = this.lhs instanceof Name ? {} : {...this.lhs.names}
90
+ return addExprNames(names, this.rhs)
91
+ }
92
+ }
93
+
94
+ class AssignOp extends Assign {
95
+ constructor(
96
+ lhs: Code,
97
+ private readonly op: Code,
98
+ rhs: SafeExpr,
99
+ sideEffects?: boolean
100
+ ) {
101
+ super(lhs, rhs, sideEffects)
102
+ }
103
+
104
+ render({_n}: CGOptions): string {
105
+ return `${this.lhs} ${this.op}= ${this.rhs};` + _n
106
+ }
107
+ }
108
+
109
+ class Label extends Node {
110
+ readonly names: UsedNames = {}
111
+ constructor(readonly label: Name) {
112
+ super()
113
+ }
114
+
115
+ render({_n}: CGOptions): string {
116
+ return `${this.label}:` + _n
117
+ }
118
+ }
119
+
120
+ class Break extends Node {
121
+ readonly names: UsedNames = {}
122
+ constructor(readonly label?: Code) {
123
+ super()
124
+ }
125
+
126
+ render({_n}: CGOptions): string {
127
+ const label = this.label ? ` ${this.label}` : ""
128
+ return `break${label};` + _n
129
+ }
130
+ }
131
+
132
+ class Throw extends Node {
133
+ constructor(readonly error: Code) {
134
+ super()
135
+ }
136
+
137
+ render({_n}: CGOptions): string {
138
+ return `throw ${this.error};` + _n
139
+ }
140
+
141
+ get names(): UsedNames {
142
+ return this.error.names
143
+ }
144
+ }
145
+
146
+ class AnyCode extends Node {
147
+ constructor(private code: SafeExpr) {
148
+ super()
149
+ }
150
+
151
+ render({_n}: CGOptions): string {
152
+ return `${this.code};` + _n
153
+ }
154
+
155
+ optimizeNodes(): this | undefined {
156
+ return `${this.code}` ? this : undefined
157
+ }
158
+
159
+ optimizeNames(names: UsedNames, constants: Constants): this {
160
+ this.code = optimizeExpr(this.code, names, constants)
161
+ return this
162
+ }
163
+
164
+ get names(): UsedNames {
165
+ return this.code instanceof _CodeOrName ? this.code.names : {}
166
+ }
167
+ }
168
+
169
+ abstract class ParentNode extends Node {
170
+ constructor(readonly nodes: ChildNode[] = []) {
171
+ super()
172
+ }
173
+
174
+ render(opts: CGOptions): string {
175
+ return this.nodes.reduce((code, n) => code + n.render(opts), "")
176
+ }
177
+
178
+ optimizeNodes(): this | ChildNode | ChildNode[] | undefined {
179
+ const {nodes} = this
180
+ let i = nodes.length
181
+ while (i--) {
182
+ const n = nodes[i].optimizeNodes()
183
+ if (Array.isArray(n)) nodes.splice(i, 1, ...n)
184
+ else if (n) nodes[i] = n
185
+ else nodes.splice(i, 1)
186
+ }
187
+ return nodes.length > 0 ? this : undefined
188
+ }
189
+
190
+ optimizeNames(names: UsedNames, constants: Constants): this | undefined {
191
+ const {nodes} = this
192
+ let i = nodes.length
193
+ while (i--) {
194
+ // iterating backwards improves 1-pass optimization
195
+ const n = nodes[i]
196
+ if (n.optimizeNames(names, constants)) continue
197
+ subtractNames(names, n.names)
198
+ nodes.splice(i, 1)
199
+ }
200
+ return nodes.length > 0 ? this : undefined
201
+ }
202
+
203
+ get names(): UsedNames {
204
+ return this.nodes.reduce((names: UsedNames, n) => addNames(names, n.names), {})
205
+ }
206
+
207
+ // get count(): number {
208
+ // return this.nodes.reduce((c, n) => c + n.count, 1)
209
+ // }
210
+ }
211
+
212
+ abstract class BlockNode extends ParentNode {
213
+ render(opts: CGOptions): string {
214
+ return "{" + opts._n + super.render(opts) + "}" + opts._n
215
+ }
216
+ }
217
+
218
+ class Root extends ParentNode {}
219
+
220
+ class Else extends BlockNode {
221
+ static readonly kind = "else"
222
+ }
223
+
224
+ class If extends BlockNode {
225
+ static readonly kind = "if"
226
+ else?: If | Else
227
+ constructor(
228
+ private condition: Code | boolean,
229
+ nodes?: ChildNode[]
230
+ ) {
231
+ super(nodes)
232
+ }
233
+
234
+ render(opts: CGOptions): string {
235
+ let code = `if(${this.condition})` + super.render(opts)
236
+ if (this.else) code += "else " + this.else.render(opts)
237
+ return code
238
+ }
239
+
240
+ optimizeNodes(): If | ChildNode[] | undefined {
241
+ super.optimizeNodes()
242
+ const cond = this.condition
243
+ if (cond === true) return this.nodes // else is ignored here
244
+ let e = this.else
245
+ if (e) {
246
+ const ns = e.optimizeNodes()
247
+ e = this.else = Array.isArray(ns) ? new Else(ns) : (ns as Else | undefined)
248
+ }
249
+ if (e) {
250
+ if (cond === false) return e instanceof If ? e : e.nodes
251
+ if (this.nodes.length) return this
252
+ return new If(not(cond), e instanceof If ? [e] : e.nodes)
253
+ }
254
+ if (cond === false || !this.nodes.length) return undefined
255
+ return this
256
+ }
257
+
258
+ optimizeNames(names: UsedNames, constants: Constants): this | undefined {
259
+ this.else = this.else?.optimizeNames(names, constants)
260
+ if (!(super.optimizeNames(names, constants) || this.else)) return
261
+ this.condition = optimizeExpr(this.condition, names, constants)
262
+ return this
263
+ }
264
+
265
+ get names(): UsedNames {
266
+ const names = super.names
267
+ addExprNames(names, this.condition)
268
+ if (this.else) addNames(names, this.else.names)
269
+ return names
270
+ }
271
+
272
+ // get count(): number {
273
+ // return super.count + (this.else?.count || 0)
274
+ // }
275
+ }
276
+
277
+ abstract class For extends BlockNode {
278
+ static readonly kind = "for"
279
+ }
280
+
281
+ class ForLoop extends For {
282
+ constructor(private iteration: Code) {
283
+ super()
284
+ }
285
+
286
+ render(opts: CGOptions): string {
287
+ return `for(${this.iteration})` + super.render(opts)
288
+ }
289
+
290
+ optimizeNames(names: UsedNames, constants: Constants): this | undefined {
291
+ if (!super.optimizeNames(names, constants)) return
292
+ this.iteration = optimizeExpr(this.iteration, names, constants)
293
+ return this
294
+ }
295
+
296
+ get names(): UsedNames {
297
+ return addNames(super.names, this.iteration.names)
298
+ }
299
+ }
300
+
301
+ class ForRange extends For {
302
+ constructor(
303
+ private readonly varKind: Name,
304
+ private readonly name: Name,
305
+ private readonly from: SafeExpr,
306
+ private readonly to: SafeExpr
307
+ ) {
308
+ super()
309
+ }
310
+
311
+ render(opts: CGOptions): string {
312
+ const varKind = opts.es5 ? varKinds.var : this.varKind
313
+ const {name, from, to} = this
314
+ return `for(${varKind} ${name}=${from}; ${name}<${to}; ${name}++)` + super.render(opts)
315
+ }
316
+
317
+ get names(): UsedNames {
318
+ const names = addExprNames(super.names, this.from)
319
+ return addExprNames(names, this.to)
320
+ }
321
+ }
322
+
323
+ class ForIter extends For {
324
+ constructor(
325
+ private readonly loop: "of" | "in",
326
+ private readonly varKind: Name,
327
+ private readonly name: Name,
328
+ private iterable: Code
329
+ ) {
330
+ super()
331
+ }
332
+
333
+ render(opts: CGOptions): string {
334
+ return `for(${this.varKind} ${this.name} ${this.loop} ${this.iterable})` + super.render(opts)
335
+ }
336
+
337
+ optimizeNames(names: UsedNames, constants: Constants): this | undefined {
338
+ if (!super.optimizeNames(names, constants)) return
339
+ this.iterable = optimizeExpr(this.iterable, names, constants)
340
+ return this
341
+ }
342
+
343
+ get names(): UsedNames {
344
+ return addNames(super.names, this.iterable.names)
345
+ }
346
+ }
347
+
348
+ class Func extends BlockNode {
349
+ static readonly kind = "func"
350
+ constructor(
351
+ public name: Name,
352
+ public args: Code,
353
+ public async?: boolean
354
+ ) {
355
+ super()
356
+ }
357
+
358
+ render(opts: CGOptions): string {
359
+ const _async = this.async ? "async " : ""
360
+ return `${_async}function ${this.name}(${this.args})` + super.render(opts)
361
+ }
362
+ }
363
+
364
+ class Return extends ParentNode {
365
+ static readonly kind = "return"
366
+
367
+ render(opts: CGOptions): string {
368
+ return "return " + super.render(opts)
369
+ }
370
+ }
371
+
372
+ class Try extends BlockNode {
373
+ catch?: Catch
374
+ finally?: Finally
375
+
376
+ render(opts: CGOptions): string {
377
+ let code = "try" + super.render(opts)
378
+ if (this.catch) code += this.catch.render(opts)
379
+ if (this.finally) code += this.finally.render(opts)
380
+ return code
381
+ }
382
+
383
+ optimizeNodes(): this {
384
+ super.optimizeNodes()
385
+ this.catch?.optimizeNodes() as Catch | undefined
386
+ this.finally?.optimizeNodes() as Finally | undefined
387
+ return this
388
+ }
389
+
390
+ optimizeNames(names: UsedNames, constants: Constants): this {
391
+ super.optimizeNames(names, constants)
392
+ this.catch?.optimizeNames(names, constants)
393
+ this.finally?.optimizeNames(names, constants)
394
+ return this
395
+ }
396
+
397
+ get names(): UsedNames {
398
+ const names = super.names
399
+ if (this.catch) addNames(names, this.catch.names)
400
+ if (this.finally) addNames(names, this.finally.names)
401
+ return names
402
+ }
403
+
404
+ // get count(): number {
405
+ // return super.count + (this.catch?.count || 0) + (this.finally?.count || 0)
406
+ // }
407
+ }
408
+
409
+ class Catch extends BlockNode {
410
+ static readonly kind = "catch"
411
+ constructor(readonly error: Name) {
412
+ super()
413
+ }
414
+
415
+ render(opts: CGOptions): string {
416
+ return `catch(${this.error})` + super.render(opts)
417
+ }
418
+ }
419
+
420
+ class Finally extends BlockNode {
421
+ static readonly kind = "finally"
422
+ render(opts: CGOptions): string {
423
+ return "finally" + super.render(opts)
424
+ }
425
+ }
426
+
427
+ type StartBlockNode = If | For | Func | Return | Try
428
+
429
+ type LeafNode = Def | Assign | Label | Break | Throw | AnyCode
430
+
431
+ type ChildNode = StartBlockNode | LeafNode
432
+
433
+ type EndBlockNodeType =
434
+ | typeof If
435
+ | typeof Else
436
+ | typeof For
437
+ | typeof Func
438
+ | typeof Return
439
+ | typeof Catch
440
+ | typeof Finally
441
+
442
+ type Constants = Record<string, SafeExpr | undefined>
443
+
444
+ export interface CodeGenOptions {
445
+ es5?: boolean
446
+ lines?: boolean
447
+ ownProperties?: boolean
448
+ }
449
+
450
+ interface CGOptions extends CodeGenOptions {
451
+ _n: "\n" | ""
452
+ }
453
+
454
+ export class CodeGen {
455
+ readonly _scope: Scope
456
+ readonly _extScope: ValueScope
457
+ readonly _values: ScopeValueSets = {}
458
+ private readonly _nodes: ParentNode[]
459
+ private readonly _blockStarts: number[] = []
460
+ private readonly _constants: Constants = {}
461
+ private readonly opts: CGOptions
462
+
463
+ constructor(extScope: ValueScope, opts: CodeGenOptions = {}) {
464
+ this.opts = {...opts, _n: opts.lines ? "\n" : ""}
465
+ this._extScope = extScope
466
+ this._scope = new Scope({parent: extScope})
467
+ this._nodes = [new Root()]
468
+ }
469
+
470
+ toString(): string {
471
+ return this._root.render(this.opts)
472
+ }
473
+
474
+ // returns unique name in the internal scope
475
+ name(prefix: string): Name {
476
+ return this._scope.name(prefix)
477
+ }
478
+
479
+ // reserves unique name in the external scope
480
+ scopeName(prefix: string): ValueScopeName {
481
+ return this._extScope.name(prefix)
482
+ }
483
+
484
+ // reserves unique name in the external scope and assigns value to it
485
+ scopeValue(prefixOrName: ValueScopeName | string, value: NameValue): Name {
486
+ const name = this._extScope.value(prefixOrName, value)
487
+ const vs = this._values[name.prefix] || (this._values[name.prefix] = new Set())
488
+ vs.add(name)
489
+ return name
490
+ }
491
+
492
+ getScopeValue(prefix: string, keyOrRef: unknown): ValueScopeName | undefined {
493
+ return this._extScope.getValue(prefix, keyOrRef)
494
+ }
495
+
496
+ // return code that assigns values in the external scope to the names that are used internally
497
+ // (same names that were returned by gen.scopeName or gen.scopeValue)
498
+ scopeRefs(scopeName: Name): Code {
499
+ return this._extScope.scopeRefs(scopeName, this._values)
500
+ }
501
+
502
+ scopeCode(): Code {
503
+ return this._extScope.scopeCode(this._values)
504
+ }
505
+
506
+ private _def(
507
+ varKind: Name,
508
+ nameOrPrefix: Name | string,
509
+ rhs?: SafeExpr,
510
+ constant?: boolean
511
+ ): Name {
512
+ const name = this._scope.toName(nameOrPrefix)
513
+ if (rhs !== undefined && constant) this._constants[name.str] = rhs
514
+ this._leafNode(new Def(varKind, name, rhs))
515
+ return name
516
+ }
517
+
518
+ // `const` declaration (`var` in es5 mode)
519
+ const(nameOrPrefix: Name | string, rhs: SafeExpr, _constant?: boolean): Name {
520
+ return this._def(varKinds.const, nameOrPrefix, rhs, _constant)
521
+ }
522
+
523
+ // `let` declaration with optional assignment (`var` in es5 mode)
524
+ let(nameOrPrefix: Name | string, rhs?: SafeExpr, _constant?: boolean): Name {
525
+ return this._def(varKinds.let, nameOrPrefix, rhs, _constant)
526
+ }
527
+
528
+ // `var` declaration with optional assignment
529
+ var(nameOrPrefix: Name | string, rhs?: SafeExpr, _constant?: boolean): Name {
530
+ return this._def(varKinds.var, nameOrPrefix, rhs, _constant)
531
+ }
532
+
533
+ // assignment code
534
+ assign(lhs: Code, rhs: SafeExpr, sideEffects?: boolean): CodeGen {
535
+ return this._leafNode(new Assign(lhs, rhs, sideEffects))
536
+ }
537
+
538
+ // `+=` code
539
+ add(lhs: Code, rhs: SafeExpr): CodeGen {
540
+ return this._leafNode(new AssignOp(lhs, operators.ADD, rhs))
541
+ }
542
+
543
+ // appends passed SafeExpr to code or executes Block
544
+ code(c: Block | SafeExpr): CodeGen {
545
+ if (typeof c == "function") c()
546
+ else if (c !== nil) this._leafNode(new AnyCode(c))
547
+ return this
548
+ }
549
+
550
+ // returns code for object literal for the passed argument list of key-value pairs
551
+ object(...keyValues: [Name | string, SafeExpr | string][]): _Code {
552
+ const code: CodeItem[] = ["{"]
553
+ for (const [key, value] of keyValues) {
554
+ if (code.length > 1) code.push(",")
555
+ code.push(key)
556
+ if (key !== value || this.opts.es5) {
557
+ code.push(":")
558
+ addCodeArg(code, value)
559
+ }
560
+ }
561
+ code.push("}")
562
+ return new _Code(code)
563
+ }
564
+
565
+ // `if` clause (or statement if `thenBody` and, optionally, `elseBody` are passed)
566
+ if(condition: Code | boolean, thenBody?: Block, elseBody?: Block): CodeGen {
567
+ this._blockNode(new If(condition))
568
+
569
+ if (thenBody && elseBody) {
570
+ this.code(thenBody).else().code(elseBody).endIf()
571
+ } else if (thenBody) {
572
+ this.code(thenBody).endIf()
573
+ } else if (elseBody) {
574
+ throw new Error('CodeGen: "else" body without "then" body')
575
+ }
576
+ return this
577
+ }
578
+
579
+ // `else if` clause - invalid without `if` or after `else` clauses
580
+ elseIf(condition: Code | boolean): CodeGen {
581
+ return this._elseNode(new If(condition))
582
+ }
583
+
584
+ // `else` clause - only valid after `if` or `else if` clauses
585
+ else(): CodeGen {
586
+ return this._elseNode(new Else())
587
+ }
588
+
589
+ // end `if` statement (needed if gen.if was used only with condition)
590
+ endIf(): CodeGen {
591
+ return this._endBlockNode(If, Else)
592
+ }
593
+
594
+ private _for(node: For, forBody?: Block): CodeGen {
595
+ this._blockNode(node)
596
+ if (forBody) this.code(forBody).endFor()
597
+ return this
598
+ }
599
+
600
+ // a generic `for` clause (or statement if `forBody` is passed)
601
+ for(iteration: Code, forBody?: Block): CodeGen {
602
+ return this._for(new ForLoop(iteration), forBody)
603
+ }
604
+
605
+ // `for` statement for a range of values
606
+ forRange(
607
+ nameOrPrefix: Name | string,
608
+ from: SafeExpr,
609
+ to: SafeExpr,
610
+ forBody: (index: Name) => void,
611
+ varKind: Code = this.opts.es5 ? varKinds.var : varKinds.let
612
+ ): CodeGen {
613
+ const name = this._scope.toName(nameOrPrefix)
614
+ return this._for(new ForRange(varKind, name, from, to), () => forBody(name))
615
+ }
616
+
617
+ // `for-of` statement (in es5 mode replace with a normal for loop)
618
+ forOf(
619
+ nameOrPrefix: Name | string,
620
+ iterable: Code,
621
+ forBody: (item: Name) => void,
622
+ varKind: Code = varKinds.const
623
+ ): CodeGen {
624
+ const name = this._scope.toName(nameOrPrefix)
625
+ if (this.opts.es5) {
626
+ const arr = iterable instanceof Name ? iterable : this.var("_arr", iterable)
627
+ return this.forRange("_i", 0, _`${arr}.length`, (i) => {
628
+ this.var(name, _`${arr}[${i}]`)
629
+ forBody(name)
630
+ })
631
+ }
632
+ return this._for(new ForIter("of", varKind, name, iterable), () => forBody(name))
633
+ }
634
+
635
+ // `for-in` statement.
636
+ // With option `ownProperties` replaced with a `for-of` loop for object keys
637
+ forIn(
638
+ nameOrPrefix: Name | string,
639
+ obj: Code,
640
+ forBody: (item: Name) => void,
641
+ varKind: Code = this.opts.es5 ? varKinds.var : varKinds.const
642
+ ): CodeGen {
643
+ if (this.opts.ownProperties) {
644
+ return this.forOf(nameOrPrefix, _`Object.keys(${obj})`, forBody)
645
+ }
646
+ const name = this._scope.toName(nameOrPrefix)
647
+ return this._for(new ForIter("in", varKind, name, obj), () => forBody(name))
648
+ }
649
+
650
+ // end `for` loop
651
+ endFor(): CodeGen {
652
+ return this._endBlockNode(For)
653
+ }
654
+
655
+ // `label` statement
656
+ label(label: Name): CodeGen {
657
+ return this._leafNode(new Label(label))
658
+ }
659
+
660
+ // `break` statement
661
+ break(label?: Code): CodeGen {
662
+ return this._leafNode(new Break(label))
663
+ }
664
+
665
+ // `return` statement
666
+ return(value: Block | SafeExpr): CodeGen {
667
+ const node = new Return()
668
+ this._blockNode(node)
669
+ this.code(value)
670
+ if (node.nodes.length !== 1) throw new Error('CodeGen: "return" should have one node')
671
+ return this._endBlockNode(Return)
672
+ }
673
+
674
+ // `try` statement
675
+ try(tryBody: Block, catchCode?: (e: Name) => void, finallyCode?: Block): CodeGen {
676
+ if (!catchCode && !finallyCode) throw new Error('CodeGen: "try" without "catch" and "finally"')
677
+ const node = new Try()
678
+ this._blockNode(node)
679
+ this.code(tryBody)
680
+ if (catchCode) {
681
+ const error = this.name("e")
682
+ this._currNode = node.catch = new Catch(error)
683
+ catchCode(error)
684
+ }
685
+ if (finallyCode) {
686
+ this._currNode = node.finally = new Finally()
687
+ this.code(finallyCode)
688
+ }
689
+ return this._endBlockNode(Catch, Finally)
690
+ }
691
+
692
+ // `throw` statement
693
+ throw(error: Code): CodeGen {
694
+ return this._leafNode(new Throw(error))
695
+ }
696
+
697
+ // start self-balancing block
698
+ block(body?: Block, nodeCount?: number): CodeGen {
699
+ this._blockStarts.push(this._nodes.length)
700
+ if (body) this.code(body).endBlock(nodeCount)
701
+ return this
702
+ }
703
+
704
+ // end the current self-balancing block
705
+ endBlock(nodeCount?: number): CodeGen {
706
+ const len = this._blockStarts.pop()
707
+ if (len === undefined) throw new Error("CodeGen: not in self-balancing block")
708
+ const toClose = this._nodes.length - len
709
+ if (toClose < 0 || (nodeCount !== undefined && toClose !== nodeCount)) {
710
+ throw new Error(`CodeGen: wrong number of nodes: ${toClose} vs ${nodeCount} expected`)
711
+ }
712
+ this._nodes.length = len
713
+ return this
714
+ }
715
+
716
+ // `function` heading (or definition if funcBody is passed)
717
+ func(name: Name, args: Code = nil, async?: boolean, funcBody?: Block): CodeGen {
718
+ this._blockNode(new Func(name, args, async))
719
+ if (funcBody) this.code(funcBody).endFunc()
720
+ return this
721
+ }
722
+
723
+ // end function definition
724
+ endFunc(): CodeGen {
725
+ return this._endBlockNode(Func)
726
+ }
727
+
728
+ optimize(n = 1): void {
729
+ while (n-- > 0) {
730
+ this._root.optimizeNodes()
731
+ this._root.optimizeNames(this._root.names, this._constants)
732
+ }
733
+ }
734
+
735
+ private _leafNode(node: LeafNode): CodeGen {
736
+ this._currNode.nodes.push(node)
737
+ return this
738
+ }
739
+
740
+ private _blockNode(node: StartBlockNode): void {
741
+ this._currNode.nodes.push(node)
742
+ this._nodes.push(node)
743
+ }
744
+
745
+ private _endBlockNode(N1: EndBlockNodeType, N2?: EndBlockNodeType): CodeGen {
746
+ const n = this._currNode
747
+ if (n instanceof N1 || (N2 && n instanceof N2)) {
748
+ this._nodes.pop()
749
+ return this
750
+ }
751
+ throw new Error(`CodeGen: not in block "${N2 ? `${N1.kind}/${N2.kind}` : N1.kind}"`)
752
+ }
753
+
754
+ private _elseNode(node: If | Else): CodeGen {
755
+ const n = this._currNode
756
+ if (!(n instanceof If)) {
757
+ throw new Error('CodeGen: "else" without "if"')
758
+ }
759
+ this._currNode = n.else = node
760
+ return this
761
+ }
762
+
763
+ private get _root(): Root {
764
+ return this._nodes[0] as Root
765
+ }
766
+
767
+ private get _currNode(): ParentNode {
768
+ const ns = this._nodes
769
+ return ns[ns.length - 1]
770
+ }
771
+
772
+ private set _currNode(node: ParentNode) {
773
+ const ns = this._nodes
774
+ ns[ns.length - 1] = node
775
+ }
776
+
777
+ // get nodeCount(): number {
778
+ // return this._root.count
779
+ // }
780
+ }
781
+
782
+ function addNames(names: UsedNames, from: UsedNames): UsedNames {
783
+ for (const n in from) names[n] = (names[n] || 0) + (from[n] || 0)
784
+ return names
785
+ }
786
+
787
+ function addExprNames(names: UsedNames, from: SafeExpr): UsedNames {
788
+ return from instanceof _CodeOrName ? addNames(names, from.names) : names
789
+ }
790
+
791
+ function optimizeExpr<T extends SafeExpr | Code>(expr: T, names: UsedNames, constants: Constants): T
792
+ function optimizeExpr(expr: SafeExpr, names: UsedNames, constants: Constants): SafeExpr {
793
+ if (expr instanceof Name) return replaceName(expr)
794
+ if (!canOptimize(expr)) return expr
795
+ return new _Code(
796
+ expr._items.reduce((items: CodeItem[], c: SafeExpr | string) => {
797
+ if (c instanceof Name) c = replaceName(c)
798
+ if (c instanceof _Code) items.push(...c._items)
799
+ else items.push(c)
800
+ return items
801
+ }, [])
802
+ )
803
+
804
+ function replaceName(n: Name): SafeExpr {
805
+ const c = constants[n.str]
806
+ if (c === undefined || names[n.str] !== 1) return n
807
+ delete names[n.str]
808
+ return c
809
+ }
810
+
811
+ function canOptimize(e: SafeExpr): e is _Code {
812
+ return (
813
+ e instanceof _Code &&
814
+ e._items.some(
815
+ (c) => c instanceof Name && names[c.str] === 1 && constants[c.str] !== undefined
816
+ )
817
+ )
818
+ }
819
+ }
820
+
821
+ function subtractNames(names: UsedNames, from: UsedNames): void {
822
+ for (const n in from) names[n] = (names[n] || 0) - (from[n] || 0)
823
+ }
824
+
825
+ export function not<T extends Code | SafeExpr>(x: T): T
826
+ export function not(x: Code | SafeExpr): Code | SafeExpr {
827
+ return typeof x == "boolean" || typeof x == "number" || x === null ? !x : _`!${par(x)}`
828
+ }
829
+
830
+ const andCode = mappend(operators.AND)
831
+
832
+ // boolean AND (&&) expression with the passed arguments
833
+ export function and(...args: Code[]): Code {
834
+ return args.reduce(andCode)
835
+ }
836
+
837
+ const orCode = mappend(operators.OR)
838
+
839
+ // boolean OR (||) expression with the passed arguments
840
+ export function or(...args: Code[]): Code {
841
+ return args.reduce(orCode)
842
+ }
843
+
844
+ type MAppend = (x: Code, y: Code) => Code
845
+
846
+ function mappend(op: Code): MAppend {
847
+ return (x, y) => (x === nil ? y : y === nil ? x : _`${par(x)} ${op} ${par(y)}`)
848
+ }
849
+
850
+ function par(x: Code): Code {
851
+ return x instanceof Name ? x : _`(${x})`
852
+ }
platform/aiml/elizabeth/e-1-first_session/claude-code-router/node_modules/ajv/lib/compile/codegen/scope.ts ADDED
@@ -0,0 +1,215 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import {_, nil, Code, Name} from "./code"
2
+
3
+ interface NameGroup {
4
+ prefix: string
5
+ index: number
6
+ }
7
+
8
+ export interface NameValue {
9
+ ref: ValueReference // this is the reference to any value that can be referred to from generated code via `globals` var in the closure
10
+ key?: unknown // any key to identify a global to avoid duplicates, if not passed ref is used
11
+ code?: Code // this is the code creating the value needed for standalone code wit_out closure - can be a primitive value, function or import (`require`)
12
+ }
13
+
14
+ export type ValueReference = unknown // possibly make CodeGen parameterized type on this type
15
+
16
+ class ValueError extends Error {
17
+ readonly value?: NameValue
18
+ constructor(name: ValueScopeName) {
19
+ super(`CodeGen: "code" for ${name} not defined`)
20
+ this.value = name.value
21
+ }
22
+ }
23
+
24
+ interface ScopeOptions {
25
+ prefixes?: Set<string>
26
+ parent?: Scope
27
+ }
28
+
29
+ interface ValueScopeOptions extends ScopeOptions {
30
+ scope: ScopeStore
31
+ es5?: boolean
32
+ lines?: boolean
33
+ }
34
+
35
+ export type ScopeStore = Record<string, ValueReference[] | undefined>
36
+
37
+ type ScopeValues = {
38
+ [Prefix in string]?: Map<unknown, ValueScopeName>
39
+ }
40
+
41
+ export type ScopeValueSets = {
42
+ [Prefix in string]?: Set<ValueScopeName>
43
+ }
44
+
45
+ export enum UsedValueState {
46
+ Started,
47
+ Completed,
48
+ }
49
+
50
+ export type UsedScopeValues = {
51
+ [Prefix in string]?: Map<ValueScopeName, UsedValueState | undefined>
52
+ }
53
+
54
+ export const varKinds = {
55
+ const: new Name("const"),
56
+ let: new Name("let"),
57
+ var: new Name("var"),
58
+ }
59
+
60
+ export class Scope {
61
+ protected readonly _names: {[Prefix in string]?: NameGroup} = {}
62
+ protected readonly _prefixes?: Set<string>
63
+ protected readonly _parent?: Scope
64
+
65
+ constructor({prefixes, parent}: ScopeOptions = {}) {
66
+ this._prefixes = prefixes
67
+ this._parent = parent
68
+ }
69
+
70
+ toName(nameOrPrefix: Name | string): Name {
71
+ return nameOrPrefix instanceof Name ? nameOrPrefix : this.name(nameOrPrefix)
72
+ }
73
+
74
+ name(prefix: string): Name {
75
+ return new Name(this._newName(prefix))
76
+ }
77
+
78
+ protected _newName(prefix: string): string {
79
+ const ng = this._names[prefix] || this._nameGroup(prefix)
80
+ return `${prefix}${ng.index++}`
81
+ }
82
+
83
+ private _nameGroup(prefix: string): NameGroup {
84
+ if (this._parent?._prefixes?.has(prefix) || (this._prefixes && !this._prefixes.has(prefix))) {
85
+ throw new Error(`CodeGen: prefix "${prefix}" is not allowed in this scope`)
86
+ }
87
+ return (this._names[prefix] = {prefix, index: 0})
88
+ }
89
+ }
90
+
91
+ interface ScopePath {
92
+ property: string
93
+ itemIndex: number
94
+ }
95
+
96
+ export class ValueScopeName extends Name {
97
+ readonly prefix: string
98
+ value?: NameValue
99
+ scopePath?: Code
100
+
101
+ constructor(prefix: string, nameStr: string) {
102
+ super(nameStr)
103
+ this.prefix = prefix
104
+ }
105
+
106
+ setValue(value: NameValue, {property, itemIndex}: ScopePath): void {
107
+ this.value = value
108
+ this.scopePath = _`.${new Name(property)}[${itemIndex}]`
109
+ }
110
+ }
111
+
112
+ interface VSOptions extends ValueScopeOptions {
113
+ _n: Code
114
+ }
115
+
116
+ const line = _`\n`
117
+
118
+ export class ValueScope extends Scope {
119
+ protected readonly _values: ScopeValues = {}
120
+ protected readonly _scope: ScopeStore
121
+ readonly opts: VSOptions
122
+
123
+ constructor(opts: ValueScopeOptions) {
124
+ super(opts)
125
+ this._scope = opts.scope
126
+ this.opts = {...opts, _n: opts.lines ? line : nil}
127
+ }
128
+
129
+ get(): ScopeStore {
130
+ return this._scope
131
+ }
132
+
133
+ name(prefix: string): ValueScopeName {
134
+ return new ValueScopeName(prefix, this._newName(prefix))
135
+ }
136
+
137
+ value(nameOrPrefix: ValueScopeName | string, value: NameValue): ValueScopeName {
138
+ if (value.ref === undefined) throw new Error("CodeGen: ref must be passed in value")
139
+ const name = this.toName(nameOrPrefix) as ValueScopeName
140
+ const {prefix} = name
141
+ const valueKey = value.key ?? value.ref
142
+ let vs = this._values[prefix]
143
+ if (vs) {
144
+ const _name = vs.get(valueKey)
145
+ if (_name) return _name
146
+ } else {
147
+ vs = this._values[prefix] = new Map()
148
+ }
149
+ vs.set(valueKey, name)
150
+
151
+ const s = this._scope[prefix] || (this._scope[prefix] = [])
152
+ const itemIndex = s.length
153
+ s[itemIndex] = value.ref
154
+ name.setValue(value, {property: prefix, itemIndex})
155
+ return name
156
+ }
157
+
158
+ getValue(prefix: string, keyOrRef: unknown): ValueScopeName | undefined {
159
+ const vs = this._values[prefix]
160
+ if (!vs) return
161
+ return vs.get(keyOrRef)
162
+ }
163
+
164
+ scopeRefs(scopeName: Name, values: ScopeValues | ScopeValueSets = this._values): Code {
165
+ return this._reduceValues(values, (name: ValueScopeName) => {
166
+ if (name.scopePath === undefined) throw new Error(`CodeGen: name "${name}" has no value`)
167
+ return _`${scopeName}${name.scopePath}`
168
+ })
169
+ }
170
+
171
+ scopeCode(
172
+ values: ScopeValues | ScopeValueSets = this._values,
173
+ usedValues?: UsedScopeValues,
174
+ getCode?: (n: ValueScopeName) => Code | undefined
175
+ ): Code {
176
+ return this._reduceValues(
177
+ values,
178
+ (name: ValueScopeName) => {
179
+ if (name.value === undefined) throw new Error(`CodeGen: name "${name}" has no value`)
180
+ return name.value.code
181
+ },
182
+ usedValues,
183
+ getCode
184
+ )
185
+ }
186
+
187
+ private _reduceValues(
188
+ values: ScopeValues | ScopeValueSets,
189
+ valueCode: (n: ValueScopeName) => Code | undefined,
190
+ usedValues: UsedScopeValues = {},
191
+ getCode?: (n: ValueScopeName) => Code | undefined
192
+ ): Code {
193
+ let code: Code = nil
194
+ for (const prefix in values) {
195
+ const vs = values[prefix]
196
+ if (!vs) continue
197
+ const nameSet = (usedValues[prefix] = usedValues[prefix] || new Map())
198
+ vs.forEach((name: ValueScopeName) => {
199
+ if (nameSet.has(name)) return
200
+ nameSet.set(name, UsedValueState.Started)
201
+ let c = valueCode(name)
202
+ if (c) {
203
+ const def = this.opts.es5 ? varKinds.var : varKinds.const
204
+ code = _`${code}${def} ${name} = ${c};${this.opts._n}`
205
+ } else if ((c = getCode?.(name))) {
206
+ code = _`${code}${c}${this.opts._n}`
207
+ } else {
208
+ throw new ValueError(name)
209
+ }
210
+ nameSet.set(name, UsedValueState.Completed)
211
+ })
212
+ }
213
+ return code
214
+ }
215
+ }
platform/aiml/elizabeth/e-1-first_session/claude-code-router/node_modules/ajv/lib/compile/errors.ts ADDED
@@ -0,0 +1,184 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import type {KeywordErrorCxt, KeywordErrorDefinition} from "../types"
2
+ import type {SchemaCxt} from "./index"
3
+ import {CodeGen, _, str, strConcat, Code, Name} from "./codegen"
4
+ import {SafeExpr} from "./codegen/code"
5
+ import {getErrorPath, Type} from "./util"
6
+ import N from "./names"
7
+
8
+ export const keywordError: KeywordErrorDefinition = {
9
+ message: ({keyword}) => str`must pass "${keyword}" keyword validation`,
10
+ }
11
+
12
+ export const keyword$DataError: KeywordErrorDefinition = {
13
+ message: ({keyword, schemaType}) =>
14
+ schemaType
15
+ ? str`"${keyword}" keyword must be ${schemaType} ($data)`
16
+ : str`"${keyword}" keyword is invalid ($data)`,
17
+ }
18
+
19
+ export interface ErrorPaths {
20
+ instancePath?: Code
21
+ schemaPath?: string
22
+ parentSchema?: boolean
23
+ }
24
+
25
+ export function reportError(
26
+ cxt: KeywordErrorCxt,
27
+ error: KeywordErrorDefinition = keywordError,
28
+ errorPaths?: ErrorPaths,
29
+ overrideAllErrors?: boolean
30
+ ): void {
31
+ const {it} = cxt
32
+ const {gen, compositeRule, allErrors} = it
33
+ const errObj = errorObjectCode(cxt, error, errorPaths)
34
+ if (overrideAllErrors ?? (compositeRule || allErrors)) {
35
+ addError(gen, errObj)
36
+ } else {
37
+ returnErrors(it, _`[${errObj}]`)
38
+ }
39
+ }
40
+
41
+ export function reportExtraError(
42
+ cxt: KeywordErrorCxt,
43
+ error: KeywordErrorDefinition = keywordError,
44
+ errorPaths?: ErrorPaths
45
+ ): void {
46
+ const {it} = cxt
47
+ const {gen, compositeRule, allErrors} = it
48
+ const errObj = errorObjectCode(cxt, error, errorPaths)
49
+ addError(gen, errObj)
50
+ if (!(compositeRule || allErrors)) {
51
+ returnErrors(it, N.vErrors)
52
+ }
53
+ }
54
+
55
+ export function resetErrorsCount(gen: CodeGen, errsCount: Name): void {
56
+ gen.assign(N.errors, errsCount)
57
+ gen.if(_`${N.vErrors} !== null`, () =>
58
+ gen.if(
59
+ errsCount,
60
+ () => gen.assign(_`${N.vErrors}.length`, errsCount),
61
+ () => gen.assign(N.vErrors, null)
62
+ )
63
+ )
64
+ }
65
+
66
+ export function extendErrors({
67
+ gen,
68
+ keyword,
69
+ schemaValue,
70
+ data,
71
+ errsCount,
72
+ it,
73
+ }: KeywordErrorCxt): void {
74
+ /* istanbul ignore if */
75
+ if (errsCount === undefined) throw new Error("ajv implementation error")
76
+ const err = gen.name("err")
77
+ gen.forRange("i", errsCount, N.errors, (i) => {
78
+ gen.const(err, _`${N.vErrors}[${i}]`)
79
+ gen.if(_`${err}.instancePath === undefined`, () =>
80
+ gen.assign(_`${err}.instancePath`, strConcat(N.instancePath, it.errorPath))
81
+ )
82
+ gen.assign(_`${err}.schemaPath`, str`${it.errSchemaPath}/${keyword}`)
83
+ if (it.opts.verbose) {
84
+ gen.assign(_`${err}.schema`, schemaValue)
85
+ gen.assign(_`${err}.data`, data)
86
+ }
87
+ })
88
+ }
89
+
90
+ function addError(gen: CodeGen, errObj: Code): void {
91
+ const err = gen.const("err", errObj)
92
+ gen.if(
93
+ _`${N.vErrors} === null`,
94
+ () => gen.assign(N.vErrors, _`[${err}]`),
95
+ _`${N.vErrors}.push(${err})`
96
+ )
97
+ gen.code(_`${N.errors}++`)
98
+ }
99
+
100
+ function returnErrors(it: SchemaCxt, errs: Code): void {
101
+ const {gen, validateName, schemaEnv} = it
102
+ if (schemaEnv.$async) {
103
+ gen.throw(_`new ${it.ValidationError as Name}(${errs})`)
104
+ } else {
105
+ gen.assign(_`${validateName}.errors`, errs)
106
+ gen.return(false)
107
+ }
108
+ }
109
+
110
+ const E = {
111
+ keyword: new Name("keyword"),
112
+ schemaPath: new Name("schemaPath"), // also used in JTD errors
113
+ params: new Name("params"),
114
+ propertyName: new Name("propertyName"),
115
+ message: new Name("message"),
116
+ schema: new Name("schema"),
117
+ parentSchema: new Name("parentSchema"),
118
+ }
119
+
120
+ function errorObjectCode(
121
+ cxt: KeywordErrorCxt,
122
+ error: KeywordErrorDefinition,
123
+ errorPaths?: ErrorPaths
124
+ ): Code {
125
+ const {createErrors} = cxt.it
126
+ if (createErrors === false) return _`{}`
127
+ return errorObject(cxt, error, errorPaths)
128
+ }
129
+
130
+ function errorObject(
131
+ cxt: KeywordErrorCxt,
132
+ error: KeywordErrorDefinition,
133
+ errorPaths: ErrorPaths = {}
134
+ ): Code {
135
+ const {gen, it} = cxt
136
+ const keyValues: [Name, SafeExpr | string][] = [
137
+ errorInstancePath(it, errorPaths),
138
+ errorSchemaPath(cxt, errorPaths),
139
+ ]
140
+ extraErrorProps(cxt, error, keyValues)
141
+ return gen.object(...keyValues)
142
+ }
143
+
144
+ function errorInstancePath({errorPath}: SchemaCxt, {instancePath}: ErrorPaths): [Name, Code] {
145
+ const instPath = instancePath
146
+ ? str`${errorPath}${getErrorPath(instancePath, Type.Str)}`
147
+ : errorPath
148
+ return [N.instancePath, strConcat(N.instancePath, instPath)]
149
+ }
150
+
151
+ function errorSchemaPath(
152
+ {keyword, it: {errSchemaPath}}: KeywordErrorCxt,
153
+ {schemaPath, parentSchema}: ErrorPaths
154
+ ): [Name, string | Code] {
155
+ let schPath = parentSchema ? errSchemaPath : str`${errSchemaPath}/${keyword}`
156
+ if (schemaPath) {
157
+ schPath = str`${schPath}${getErrorPath(schemaPath, Type.Str)}`
158
+ }
159
+ return [E.schemaPath, schPath]
160
+ }
161
+
162
+ function extraErrorProps(
163
+ cxt: KeywordErrorCxt,
164
+ {params, message}: KeywordErrorDefinition,
165
+ keyValues: [Name, SafeExpr | string][]
166
+ ): void {
167
+ const {keyword, data, schemaValue, it} = cxt
168
+ const {opts, propertyName, topSchemaRef, schemaPath} = it
169
+ keyValues.push(
170
+ [E.keyword, keyword],
171
+ [E.params, typeof params == "function" ? params(cxt) : params || _`{}`]
172
+ )
173
+ if (opts.messages) {
174
+ keyValues.push([E.message, typeof message == "function" ? message(cxt) : message])
175
+ }
176
+ if (opts.verbose) {
177
+ keyValues.push(
178
+ [E.schema, schemaValue],
179
+ [E.parentSchema, _`${topSchemaRef}${schemaPath}`],
180
+ [N.data, data]
181
+ )
182
+ }
183
+ if (propertyName) keyValues.push([E.propertyName, propertyName])
184
+ }
platform/aiml/elizabeth/e-1-first_session/claude-code-router/node_modules/ajv/lib/compile/index.ts ADDED
@@ -0,0 +1,324 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import type {
2
+ AnySchema,
3
+ AnySchemaObject,
4
+ AnyValidateFunction,
5
+ AsyncValidateFunction,
6
+ EvaluatedProperties,
7
+ EvaluatedItems,
8
+ } from "../types"
9
+ import type Ajv from "../core"
10
+ import type {InstanceOptions} from "../core"
11
+ import {CodeGen, _, nil, stringify, Name, Code, ValueScopeName} from "./codegen"
12
+ import ValidationError from "../runtime/validation_error"
13
+ import N from "./names"
14
+ import {LocalRefs, getFullPath, _getFullPath, inlineRef, normalizeId, resolveUrl} from "./resolve"
15
+ import {schemaHasRulesButRef, unescapeFragment} from "./util"
16
+ import {validateFunctionCode} from "./validate"
17
+ import {URIComponent} from "fast-uri"
18
+ import {JSONType} from "./rules"
19
+
20
+ export type SchemaRefs = {
21
+ [Ref in string]?: SchemaEnv | AnySchema
22
+ }
23
+
24
+ export interface SchemaCxt {
25
+ readonly gen: CodeGen
26
+ readonly allErrors?: boolean // validation mode - whether to collect all errors or break on error
27
+ readonly data: Name // Name with reference to the current part of data instance
28
+ readonly parentData: Name // should be used in keywords modifying data
29
+ readonly parentDataProperty: Code | number // should be used in keywords modifying data
30
+ readonly dataNames: Name[]
31
+ readonly dataPathArr: (Code | number)[]
32
+ readonly dataLevel: number // the level of the currently validated data,
33
+ // it can be used to access both the property names and the data on all levels from the top.
34
+ dataTypes: JSONType[] // data types applied to the current part of data instance
35
+ definedProperties: Set<string> // set of properties to keep track of for required checks
36
+ readonly topSchemaRef: Code
37
+ readonly validateName: Name
38
+ evaluated?: Name
39
+ readonly ValidationError?: Name
40
+ readonly schema: AnySchema // current schema object - equal to parentSchema passed via KeywordCxt
41
+ readonly schemaEnv: SchemaEnv
42
+ readonly rootId: string
43
+ baseId: string // the current schema base URI that should be used as the base for resolving URIs in references (\$ref)
44
+ readonly schemaPath: Code // the run-time expression that evaluates to the property name of the current schema
45
+ readonly errSchemaPath: string // this is actual string, should not be changed to Code
46
+ readonly errorPath: Code
47
+ readonly propertyName?: Name
48
+ readonly compositeRule?: boolean // true indicates that the current schema is inside the compound keyword,
49
+ // where failing some rule doesn't mean validation failure (`anyOf`, `oneOf`, `not`, `if`).
50
+ // This flag is used to determine whether you can return validation result immediately after any error in case the option `allErrors` is not `true.
51
+ // You only need to use it if you have many steps in your keywords and potentially can define multiple errors.
52
+ props?: EvaluatedProperties | Name // properties evaluated by this schema - used by parent schema or assigned to validation function
53
+ items?: EvaluatedItems | Name // last item evaluated by this schema - used by parent schema or assigned to validation function
54
+ jtdDiscriminator?: string
55
+ jtdMetadata?: boolean
56
+ readonly createErrors?: boolean
57
+ readonly opts: InstanceOptions // Ajv instance option.
58
+ readonly self: Ajv // current Ajv instance
59
+ }
60
+
61
+ export interface SchemaObjCxt extends SchemaCxt {
62
+ readonly schema: AnySchemaObject
63
+ }
64
+ interface SchemaEnvArgs {
65
+ readonly schema: AnySchema
66
+ readonly schemaId?: "$id" | "id"
67
+ readonly root?: SchemaEnv
68
+ readonly baseId?: string
69
+ readonly schemaPath?: string
70
+ readonly localRefs?: LocalRefs
71
+ readonly meta?: boolean
72
+ }
73
+
74
+ export class SchemaEnv implements SchemaEnvArgs {
75
+ readonly schema: AnySchema
76
+ readonly schemaId?: "$id" | "id"
77
+ readonly root: SchemaEnv
78
+ baseId: string // TODO possibly, it should be readonly
79
+ schemaPath?: string
80
+ localRefs?: LocalRefs
81
+ readonly meta?: boolean
82
+ readonly $async?: boolean // true if the current schema is asynchronous.
83
+ readonly refs: SchemaRefs = {}
84
+ readonly dynamicAnchors: {[Ref in string]?: true} = {}
85
+ validate?: AnyValidateFunction
86
+ validateName?: ValueScopeName
87
+ serialize?: (data: unknown) => string
88
+ serializeName?: ValueScopeName
89
+ parse?: (data: string) => unknown
90
+ parseName?: ValueScopeName
91
+
92
+ constructor(env: SchemaEnvArgs) {
93
+ let schema: AnySchemaObject | undefined
94
+ if (typeof env.schema == "object") schema = env.schema
95
+ this.schema = env.schema
96
+ this.schemaId = env.schemaId
97
+ this.root = env.root || this
98
+ this.baseId = env.baseId ?? normalizeId(schema?.[env.schemaId || "$id"])
99
+ this.schemaPath = env.schemaPath
100
+ this.localRefs = env.localRefs
101
+ this.meta = env.meta
102
+ this.$async = schema?.$async
103
+ this.refs = {}
104
+ }
105
+ }
106
+
107
+ // let codeSize = 0
108
+ // let nodeCount = 0
109
+
110
+ // Compiles schema in SchemaEnv
111
+ export function compileSchema(this: Ajv, sch: SchemaEnv): SchemaEnv {
112
+ // TODO refactor - remove compilations
113
+ const _sch = getCompilingSchema.call(this, sch)
114
+ if (_sch) return _sch
115
+ const rootId = getFullPath(this.opts.uriResolver, sch.root.baseId) // TODO if getFullPath removed 1 tests fails
116
+ const {es5, lines} = this.opts.code
117
+ const {ownProperties} = this.opts
118
+ const gen = new CodeGen(this.scope, {es5, lines, ownProperties})
119
+ let _ValidationError
120
+ if (sch.$async) {
121
+ _ValidationError = gen.scopeValue("Error", {
122
+ ref: ValidationError,
123
+ code: _`require("ajv/dist/runtime/validation_error").default`,
124
+ })
125
+ }
126
+
127
+ const validateName = gen.scopeName("validate")
128
+ sch.validateName = validateName
129
+
130
+ const schemaCxt: SchemaCxt = {
131
+ gen,
132
+ allErrors: this.opts.allErrors,
133
+ data: N.data,
134
+ parentData: N.parentData,
135
+ parentDataProperty: N.parentDataProperty,
136
+ dataNames: [N.data],
137
+ dataPathArr: [nil], // TODO can its length be used as dataLevel if nil is removed?
138
+ dataLevel: 0,
139
+ dataTypes: [],
140
+ definedProperties: new Set<string>(),
141
+ topSchemaRef: gen.scopeValue(
142
+ "schema",
143
+ this.opts.code.source === true
144
+ ? {ref: sch.schema, code: stringify(sch.schema)}
145
+ : {ref: sch.schema}
146
+ ),
147
+ validateName,
148
+ ValidationError: _ValidationError,
149
+ schema: sch.schema,
150
+ schemaEnv: sch,
151
+ rootId,
152
+ baseId: sch.baseId || rootId,
153
+ schemaPath: nil,
154
+ errSchemaPath: sch.schemaPath || (this.opts.jtd ? "" : "#"),
155
+ errorPath: _`""`,
156
+ opts: this.opts,
157
+ self: this,
158
+ }
159
+
160
+ let sourceCode: string | undefined
161
+ try {
162
+ this._compilations.add(sch)
163
+ validateFunctionCode(schemaCxt)
164
+ gen.optimize(this.opts.code.optimize)
165
+ // gen.optimize(1)
166
+ const validateCode = gen.toString()
167
+ sourceCode = `${gen.scopeRefs(N.scope)}return ${validateCode}`
168
+ // console.log((codeSize += sourceCode.length), (nodeCount += gen.nodeCount))
169
+ if (this.opts.code.process) sourceCode = this.opts.code.process(sourceCode, sch)
170
+ // console.log("\n\n\n *** \n", sourceCode)
171
+ const makeValidate = new Function(`${N.self}`, `${N.scope}`, sourceCode)
172
+ const validate: AnyValidateFunction = makeValidate(this, this.scope.get())
173
+ this.scope.value(validateName, {ref: validate})
174
+
175
+ validate.errors = null
176
+ validate.schema = sch.schema
177
+ validate.schemaEnv = sch
178
+ if (sch.$async) (validate as AsyncValidateFunction).$async = true
179
+ if (this.opts.code.source === true) {
180
+ validate.source = {validateName, validateCode, scopeValues: gen._values}
181
+ }
182
+ if (this.opts.unevaluated) {
183
+ const {props, items} = schemaCxt
184
+ validate.evaluated = {
185
+ props: props instanceof Name ? undefined : props,
186
+ items: items instanceof Name ? undefined : items,
187
+ dynamicProps: props instanceof Name,
188
+ dynamicItems: items instanceof Name,
189
+ }
190
+ if (validate.source) validate.source.evaluated = stringify(validate.evaluated)
191
+ }
192
+ sch.validate = validate
193
+ return sch
194
+ } catch (e) {
195
+ delete sch.validate
196
+ delete sch.validateName
197
+ if (sourceCode) this.logger.error("Error compiling schema, function code:", sourceCode)
198
+ // console.log("\n\n\n *** \n", sourceCode, this.opts)
199
+ throw e
200
+ } finally {
201
+ this._compilations.delete(sch)
202
+ }
203
+ }
204
+
205
+ export function resolveRef(
206
+ this: Ajv,
207
+ root: SchemaEnv,
208
+ baseId: string,
209
+ ref: string
210
+ ): AnySchema | SchemaEnv | undefined {
211
+ ref = resolveUrl(this.opts.uriResolver, baseId, ref)
212
+ const schOrFunc = root.refs[ref]
213
+ if (schOrFunc) return schOrFunc
214
+
215
+ let _sch = resolve.call(this, root, ref)
216
+ if (_sch === undefined) {
217
+ const schema = root.localRefs?.[ref] // TODO maybe localRefs should hold SchemaEnv
218
+ const {schemaId} = this.opts
219
+ if (schema) _sch = new SchemaEnv({schema, schemaId, root, baseId})
220
+ }
221
+
222
+ if (_sch === undefined) return
223
+ return (root.refs[ref] = inlineOrCompile.call(this, _sch))
224
+ }
225
+
226
+ function inlineOrCompile(this: Ajv, sch: SchemaEnv): AnySchema | SchemaEnv {
227
+ if (inlineRef(sch.schema, this.opts.inlineRefs)) return sch.schema
228
+ return sch.validate ? sch : compileSchema.call(this, sch)
229
+ }
230
+
231
+ // Index of schema compilation in the currently compiled list
232
+ export function getCompilingSchema(this: Ajv, schEnv: SchemaEnv): SchemaEnv | void {
233
+ for (const sch of this._compilations) {
234
+ if (sameSchemaEnv(sch, schEnv)) return sch
235
+ }
236
+ }
237
+
238
+ function sameSchemaEnv(s1: SchemaEnv, s2: SchemaEnv): boolean {
239
+ return s1.schema === s2.schema && s1.root === s2.root && s1.baseId === s2.baseId
240
+ }
241
+
242
+ // resolve and compile the references ($ref)
243
+ // TODO returns AnySchemaObject (if the schema can be inlined) or validation function
244
+ function resolve(
245
+ this: Ajv,
246
+ root: SchemaEnv, // information about the root schema for the current schema
247
+ ref: string // reference to resolve
248
+ ): SchemaEnv | undefined {
249
+ let sch
250
+ while (typeof (sch = this.refs[ref]) == "string") ref = sch
251
+ return sch || this.schemas[ref] || resolveSchema.call(this, root, ref)
252
+ }
253
+
254
+ // Resolve schema, its root and baseId
255
+ export function resolveSchema(
256
+ this: Ajv,
257
+ root: SchemaEnv, // root object with properties schema, refs TODO below SchemaEnv is assigned to it
258
+ ref: string // reference to resolve
259
+ ): SchemaEnv | undefined {
260
+ const p = this.opts.uriResolver.parse(ref)
261
+ const refPath = _getFullPath(this.opts.uriResolver, p)
262
+ let baseId = getFullPath(this.opts.uriResolver, root.baseId, undefined)
263
+ // TODO `Object.keys(root.schema).length > 0` should not be needed - but removing breaks 2 tests
264
+ if (Object.keys(root.schema).length > 0 && refPath === baseId) {
265
+ return getJsonPointer.call(this, p, root)
266
+ }
267
+
268
+ const id = normalizeId(refPath)
269
+ const schOrRef = this.refs[id] || this.schemas[id]
270
+ if (typeof schOrRef == "string") {
271
+ const sch = resolveSchema.call(this, root, schOrRef)
272
+ if (typeof sch?.schema !== "object") return
273
+ return getJsonPointer.call(this, p, sch)
274
+ }
275
+
276
+ if (typeof schOrRef?.schema !== "object") return
277
+ if (!schOrRef.validate) compileSchema.call(this, schOrRef)
278
+ if (id === normalizeId(ref)) {
279
+ const {schema} = schOrRef
280
+ const {schemaId} = this.opts
281
+ const schId = schema[schemaId]
282
+ if (schId) baseId = resolveUrl(this.opts.uriResolver, baseId, schId)
283
+ return new SchemaEnv({schema, schemaId, root, baseId})
284
+ }
285
+ return getJsonPointer.call(this, p, schOrRef)
286
+ }
287
+
288
+ const PREVENT_SCOPE_CHANGE = new Set([
289
+ "properties",
290
+ "patternProperties",
291
+ "enum",
292
+ "dependencies",
293
+ "definitions",
294
+ ])
295
+
296
+ function getJsonPointer(
297
+ this: Ajv,
298
+ parsedRef: URIComponent,
299
+ {baseId, schema, root}: SchemaEnv
300
+ ): SchemaEnv | undefined {
301
+ if (parsedRef.fragment?.[0] !== "/") return
302
+ for (const part of parsedRef.fragment.slice(1).split("/")) {
303
+ if (typeof schema === "boolean") return
304
+ const partSchema = schema[unescapeFragment(part)]
305
+ if (partSchema === undefined) return
306
+ schema = partSchema
307
+ // TODO PREVENT_SCOPE_CHANGE could be defined in keyword def?
308
+ const schId = typeof schema === "object" && schema[this.opts.schemaId]
309
+ if (!PREVENT_SCOPE_CHANGE.has(part) && schId) {
310
+ baseId = resolveUrl(this.opts.uriResolver, baseId, schId)
311
+ }
312
+ }
313
+ let env: SchemaEnv | undefined
314
+ if (typeof schema != "boolean" && schema.$ref && !schemaHasRulesButRef(schema, this.RULES)) {
315
+ const $ref = resolveUrl(this.opts.uriResolver, baseId, schema.$ref)
316
+ env = resolveSchema.call(this, root, $ref)
317
+ }
318
+ // even though resolution failed we need to return SchemaEnv to throw exception
319
+ // so that compileAsync loads missing schema.
320
+ const {schemaId} = this.opts
321
+ env = env || new SchemaEnv({schema, schemaId, root, baseId})
322
+ if (env.schema !== env.root.schema) return env
323
+ return undefined
324
+ }
platform/aiml/elizabeth/e-1-first_session/claude-code-router/node_modules/ajv/lib/compile/jtd/parse.ts ADDED
@@ -0,0 +1,411 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import type Ajv from "../../core"
2
+ import type {SchemaObject} from "../../types"
3
+ import {jtdForms, JTDForm, SchemaObjectMap} from "./types"
4
+ import {SchemaEnv, getCompilingSchema} from ".."
5
+ import {_, str, and, or, nil, not, CodeGen, Code, Name, SafeExpr} from "../codegen"
6
+ import MissingRefError from "../ref_error"
7
+ import N from "../names"
8
+ import {hasPropFunc} from "../../vocabularies/code"
9
+ import {hasRef} from "../../vocabularies/jtd/ref"
10
+ import {intRange, IntType} from "../../vocabularies/jtd/type"
11
+ import {parseJson, parseJsonNumber, parseJsonString} from "../../runtime/parseJson"
12
+ import {useFunc} from "../util"
13
+ import validTimestamp from "../../runtime/timestamp"
14
+
15
+ type GenParse = (cxt: ParseCxt) => void
16
+
17
+ const genParse: {[F in JTDForm]: GenParse} = {
18
+ elements: parseElements,
19
+ values: parseValues,
20
+ discriminator: parseDiscriminator,
21
+ properties: parseProperties,
22
+ optionalProperties: parseProperties,
23
+ enum: parseEnum,
24
+ type: parseType,
25
+ ref: parseRef,
26
+ }
27
+
28
+ interface ParseCxt {
29
+ readonly gen: CodeGen
30
+ readonly self: Ajv // current Ajv instance
31
+ readonly schemaEnv: SchemaEnv
32
+ readonly definitions: SchemaObjectMap
33
+ schema: SchemaObject
34
+ data: Code
35
+ parseName: Name
36
+ char: Name
37
+ }
38
+
39
+ export default function compileParser(
40
+ this: Ajv,
41
+ sch: SchemaEnv,
42
+ definitions: SchemaObjectMap
43
+ ): SchemaEnv {
44
+ const _sch = getCompilingSchema.call(this, sch)
45
+ if (_sch) return _sch
46
+ const {es5, lines} = this.opts.code
47
+ const {ownProperties} = this.opts
48
+ const gen = new CodeGen(this.scope, {es5, lines, ownProperties})
49
+ const parseName = gen.scopeName("parse")
50
+ const cxt: ParseCxt = {
51
+ self: this,
52
+ gen,
53
+ schema: sch.schema as SchemaObject,
54
+ schemaEnv: sch,
55
+ definitions,
56
+ data: N.data,
57
+ parseName,
58
+ char: gen.name("c"),
59
+ }
60
+
61
+ let sourceCode: string | undefined
62
+ try {
63
+ this._compilations.add(sch)
64
+ sch.parseName = parseName
65
+ parserFunction(cxt)
66
+ gen.optimize(this.opts.code.optimize)
67
+ const parseFuncCode = gen.toString()
68
+ sourceCode = `${gen.scopeRefs(N.scope)}return ${parseFuncCode}`
69
+ const makeParse = new Function(`${N.scope}`, sourceCode)
70
+ const parse: (json: string) => unknown = makeParse(this.scope.get())
71
+ this.scope.value(parseName, {ref: parse})
72
+ sch.parse = parse
73
+ } catch (e) {
74
+ if (sourceCode) this.logger.error("Error compiling parser, function code:", sourceCode)
75
+ delete sch.parse
76
+ delete sch.parseName
77
+ throw e
78
+ } finally {
79
+ this._compilations.delete(sch)
80
+ }
81
+ return sch
82
+ }
83
+
84
+ const undef = _`undefined`
85
+
86
+ function parserFunction(cxt: ParseCxt): void {
87
+ const {gen, parseName, char} = cxt
88
+ gen.func(parseName, _`${N.json}, ${N.jsonPos}, ${N.jsonPart}`, false, () => {
89
+ gen.let(N.data)
90
+ gen.let(char)
91
+ gen.assign(_`${parseName}.message`, undef)
92
+ gen.assign(_`${parseName}.position`, undef)
93
+ gen.assign(N.jsonPos, _`${N.jsonPos} || 0`)
94
+ gen.const(N.jsonLen, _`${N.json}.length`)
95
+ parseCode(cxt)
96
+ skipWhitespace(cxt)
97
+ gen.if(N.jsonPart, () => {
98
+ gen.assign(_`${parseName}.position`, N.jsonPos)
99
+ gen.return(N.data)
100
+ })
101
+ gen.if(_`${N.jsonPos} === ${N.jsonLen}`, () => gen.return(N.data))
102
+ jsonSyntaxError(cxt)
103
+ })
104
+ }
105
+
106
+ function parseCode(cxt: ParseCxt): void {
107
+ let form: JTDForm | undefined
108
+ for (const key of jtdForms) {
109
+ if (key in cxt.schema) {
110
+ form = key
111
+ break
112
+ }
113
+ }
114
+ if (form) parseNullable(cxt, genParse[form])
115
+ else parseEmpty(cxt)
116
+ }
117
+
118
+ const parseBoolean = parseBooleanToken(true, parseBooleanToken(false, jsonSyntaxError))
119
+
120
+ function parseNullable(cxt: ParseCxt, parseForm: GenParse): void {
121
+ const {gen, schema, data} = cxt
122
+ if (!schema.nullable) return parseForm(cxt)
123
+ tryParseToken(cxt, "null", parseForm, () => gen.assign(data, null))
124
+ }
125
+
126
+ function parseElements(cxt: ParseCxt): void {
127
+ const {gen, schema, data} = cxt
128
+ parseToken(cxt, "[")
129
+ const ix = gen.let("i", 0)
130
+ gen.assign(data, _`[]`)
131
+ parseItems(cxt, "]", () => {
132
+ const el = gen.let("el")
133
+ parseCode({...cxt, schema: schema.elements, data: el})
134
+ gen.assign(_`${data}[${ix}++]`, el)
135
+ })
136
+ }
137
+
138
+ function parseValues(cxt: ParseCxt): void {
139
+ const {gen, schema, data} = cxt
140
+ parseToken(cxt, "{")
141
+ gen.assign(data, _`{}`)
142
+ parseItems(cxt, "}", () => parseKeyValue(cxt, schema.values))
143
+ }
144
+
145
+ function parseItems(cxt: ParseCxt, endToken: string, block: () => void): void {
146
+ tryParseItems(cxt, endToken, block)
147
+ parseToken(cxt, endToken)
148
+ }
149
+
150
+ function tryParseItems(cxt: ParseCxt, endToken: string, block: () => void): void {
151
+ const {gen} = cxt
152
+ gen.for(_`;${N.jsonPos}<${N.jsonLen} && ${jsonSlice(1)}!==${endToken};`, () => {
153
+ block()
154
+ tryParseToken(cxt, ",", () => gen.break(), hasItem)
155
+ })
156
+
157
+ function hasItem(): void {
158
+ tryParseToken(cxt, endToken, () => {}, jsonSyntaxError)
159
+ }
160
+ }
161
+
162
+ function parseKeyValue(cxt: ParseCxt, schema: SchemaObject): void {
163
+ const {gen} = cxt
164
+ const key = gen.let("key")
165
+ parseString({...cxt, data: key})
166
+ parseToken(cxt, ":")
167
+ parsePropertyValue(cxt, key, schema)
168
+ }
169
+
170
+ function parseDiscriminator(cxt: ParseCxt): void {
171
+ const {gen, data, schema} = cxt
172
+ const {discriminator, mapping} = schema
173
+ parseToken(cxt, "{")
174
+ gen.assign(data, _`{}`)
175
+ const startPos = gen.const("pos", N.jsonPos)
176
+ const value = gen.let("value")
177
+ const tag = gen.let("tag")
178
+ tryParseItems(cxt, "}", () => {
179
+ const key = gen.let("key")
180
+ parseString({...cxt, data: key})
181
+ parseToken(cxt, ":")
182
+ gen.if(
183
+ _`${key} === ${discriminator}`,
184
+ () => {
185
+ parseString({...cxt, data: tag})
186
+ gen.assign(_`${data}[${key}]`, tag)
187
+ gen.break()
188
+ },
189
+ () => parseEmpty({...cxt, data: value}) // can be discarded/skipped
190
+ )
191
+ })
192
+ gen.assign(N.jsonPos, startPos)
193
+ gen.if(_`${tag} === undefined`)
194
+ parsingError(cxt, str`discriminator tag not found`)
195
+ for (const tagValue in mapping) {
196
+ gen.elseIf(_`${tag} === ${tagValue}`)
197
+ parseSchemaProperties({...cxt, schema: mapping[tagValue]}, discriminator)
198
+ }
199
+ gen.else()
200
+ parsingError(cxt, str`discriminator value not in schema`)
201
+ gen.endIf()
202
+ }
203
+
204
+ function parseProperties(cxt: ParseCxt): void {
205
+ const {gen, data} = cxt
206
+ parseToken(cxt, "{")
207
+ gen.assign(data, _`{}`)
208
+ parseSchemaProperties(cxt)
209
+ }
210
+
211
+ function parseSchemaProperties(cxt: ParseCxt, discriminator?: string): void {
212
+ const {gen, schema, data} = cxt
213
+ const {properties, optionalProperties, additionalProperties} = schema
214
+ parseItems(cxt, "}", () => {
215
+ const key = gen.let("key")
216
+ parseString({...cxt, data: key})
217
+ parseToken(cxt, ":")
218
+ gen.if(false)
219
+ parseDefinedProperty(cxt, key, properties)
220
+ parseDefinedProperty(cxt, key, optionalProperties)
221
+ if (discriminator) {
222
+ gen.elseIf(_`${key} === ${discriminator}`)
223
+ const tag = gen.let("tag")
224
+ parseString({...cxt, data: tag}) // can be discarded, it is already assigned
225
+ }
226
+ gen.else()
227
+ if (additionalProperties) {
228
+ parseEmpty({...cxt, data: _`${data}[${key}]`})
229
+ } else {
230
+ parsingError(cxt, str`property ${key} not allowed`)
231
+ }
232
+ gen.endIf()
233
+ })
234
+ if (properties) {
235
+ const hasProp = hasPropFunc(gen)
236
+ const allProps: Code = and(
237
+ ...Object.keys(properties).map((p): Code => _`${hasProp}.call(${data}, ${p})`)
238
+ )
239
+ gen.if(not(allProps), () => parsingError(cxt, str`missing required properties`))
240
+ }
241
+ }
242
+
243
+ function parseDefinedProperty(cxt: ParseCxt, key: Name, schemas: SchemaObjectMap = {}): void {
244
+ const {gen} = cxt
245
+ for (const prop in schemas) {
246
+ gen.elseIf(_`${key} === ${prop}`)
247
+ parsePropertyValue(cxt, key, schemas[prop] as SchemaObject)
248
+ }
249
+ }
250
+
251
+ function parsePropertyValue(cxt: ParseCxt, key: Name, schema: SchemaObject): void {
252
+ parseCode({...cxt, schema, data: _`${cxt.data}[${key}]`})
253
+ }
254
+
255
+ function parseType(cxt: ParseCxt): void {
256
+ const {gen, schema, data, self} = cxt
257
+ switch (schema.type) {
258
+ case "boolean":
259
+ parseBoolean(cxt)
260
+ break
261
+ case "string":
262
+ parseString(cxt)
263
+ break
264
+ case "timestamp": {
265
+ parseString(cxt)
266
+ const vts = useFunc(gen, validTimestamp)
267
+ const {allowDate, parseDate} = self.opts
268
+ const notValid = allowDate ? _`!${vts}(${data}, true)` : _`!${vts}(${data})`
269
+ const fail: Code = parseDate
270
+ ? or(notValid, _`(${data} = new Date(${data}), false)`, _`isNaN(${data}.valueOf())`)
271
+ : notValid
272
+ gen.if(fail, () => parsingError(cxt, str`invalid timestamp`))
273
+ break
274
+ }
275
+ case "float32":
276
+ case "float64":
277
+ parseNumber(cxt)
278
+ break
279
+ default: {
280
+ const t = schema.type as IntType
281
+ if (!self.opts.int32range && (t === "int32" || t === "uint32")) {
282
+ parseNumber(cxt, 16) // 2 ** 53 - max safe integer
283
+ if (t === "uint32") {
284
+ gen.if(_`${data} < 0`, () => parsingError(cxt, str`integer out of range`))
285
+ }
286
+ } else {
287
+ const [min, max, maxDigits] = intRange[t]
288
+ parseNumber(cxt, maxDigits)
289
+ gen.if(_`${data} < ${min} || ${data} > ${max}`, () =>
290
+ parsingError(cxt, str`integer out of range`)
291
+ )
292
+ }
293
+ }
294
+ }
295
+ }
296
+
297
+ function parseString(cxt: ParseCxt): void {
298
+ parseToken(cxt, '"')
299
+ parseWith(cxt, parseJsonString)
300
+ }
301
+
302
+ function parseEnum(cxt: ParseCxt): void {
303
+ const {gen, data, schema} = cxt
304
+ const enumSch = schema.enum
305
+ parseToken(cxt, '"')
306
+ // TODO loopEnum
307
+ gen.if(false)
308
+ for (const value of enumSch) {
309
+ const valueStr = JSON.stringify(value).slice(1) // remove starting quote
310
+ gen.elseIf(_`${jsonSlice(valueStr.length)} === ${valueStr}`)
311
+ gen.assign(data, str`${value}`)
312
+ gen.add(N.jsonPos, valueStr.length)
313
+ }
314
+ gen.else()
315
+ jsonSyntaxError(cxt)
316
+ gen.endIf()
317
+ }
318
+
319
+ function parseNumber(cxt: ParseCxt, maxDigits?: number): void {
320
+ const {gen} = cxt
321
+ skipWhitespace(cxt)
322
+ gen.if(
323
+ _`"-0123456789".indexOf(${jsonSlice(1)}) < 0`,
324
+ () => jsonSyntaxError(cxt),
325
+ () => parseWith(cxt, parseJsonNumber, maxDigits)
326
+ )
327
+ }
328
+
329
+ function parseBooleanToken(bool: boolean, fail: GenParse): GenParse {
330
+ return (cxt) => {
331
+ const {gen, data} = cxt
332
+ tryParseToken(
333
+ cxt,
334
+ `${bool}`,
335
+ () => fail(cxt),
336
+ () => gen.assign(data, bool)
337
+ )
338
+ }
339
+ }
340
+
341
+ function parseRef(cxt: ParseCxt): void {
342
+ const {gen, self, definitions, schema, schemaEnv} = cxt
343
+ const {ref} = schema
344
+ const refSchema = definitions[ref]
345
+ if (!refSchema) throw new MissingRefError(self.opts.uriResolver, "", ref, `No definition ${ref}`)
346
+ if (!hasRef(refSchema)) return parseCode({...cxt, schema: refSchema})
347
+ const {root} = schemaEnv
348
+ const sch = compileParser.call(self, new SchemaEnv({schema: refSchema, root}), definitions)
349
+ partialParse(cxt, getParser(gen, sch), true)
350
+ }
351
+
352
+ function getParser(gen: CodeGen, sch: SchemaEnv): Code {
353
+ return sch.parse
354
+ ? gen.scopeValue("parse", {ref: sch.parse})
355
+ : _`${gen.scopeValue("wrapper", {ref: sch})}.parse`
356
+ }
357
+
358
+ function parseEmpty(cxt: ParseCxt): void {
359
+ parseWith(cxt, parseJson)
360
+ }
361
+
362
+ function parseWith(cxt: ParseCxt, parseFunc: {code: string}, args?: SafeExpr): void {
363
+ partialParse(cxt, useFunc(cxt.gen, parseFunc), args)
364
+ }
365
+
366
+ function partialParse(cxt: ParseCxt, parseFunc: Name, args?: SafeExpr): void {
367
+ const {gen, data} = cxt
368
+ gen.assign(data, _`${parseFunc}(${N.json}, ${N.jsonPos}${args ? _`, ${args}` : nil})`)
369
+ gen.assign(N.jsonPos, _`${parseFunc}.position`)
370
+ gen.if(_`${data} === undefined`, () => parsingError(cxt, _`${parseFunc}.message`))
371
+ }
372
+
373
+ function parseToken(cxt: ParseCxt, tok: string): void {
374
+ tryParseToken(cxt, tok, jsonSyntaxError)
375
+ }
376
+
377
+ function tryParseToken(cxt: ParseCxt, tok: string, fail: GenParse, success?: GenParse): void {
378
+ const {gen} = cxt
379
+ const n = tok.length
380
+ skipWhitespace(cxt)
381
+ gen.if(
382
+ _`${jsonSlice(n)} === ${tok}`,
383
+ () => {
384
+ gen.add(N.jsonPos, n)
385
+ success?.(cxt)
386
+ },
387
+ () => fail(cxt)
388
+ )
389
+ }
390
+
391
+ function skipWhitespace({gen, char: c}: ParseCxt): void {
392
+ gen.code(
393
+ _`while((${c}=${N.json}[${N.jsonPos}],${c}===" "||${c}==="\\n"||${c}==="\\r"||${c}==="\\t"))${N.jsonPos}++;`
394
+ )
395
+ }
396
+
397
+ function jsonSlice(len: number | Name): Code {
398
+ return len === 1
399
+ ? _`${N.json}[${N.jsonPos}]`
400
+ : _`${N.json}.slice(${N.jsonPos}, ${N.jsonPos}+${len})`
401
+ }
402
+
403
+ function jsonSyntaxError(cxt: ParseCxt): void {
404
+ parsingError(cxt, _`"unexpected token " + ${N.json}[${N.jsonPos}]`)
405
+ }
406
+
407
+ function parsingError({gen, parseName}: ParseCxt, msg: Code): void {
408
+ gen.assign(_`${parseName}.message`, msg)
409
+ gen.assign(_`${parseName}.position`, N.jsonPos)
410
+ gen.return(undef)
411
+ }
platform/aiml/elizabeth/e-1-first_session/claude-code-router/node_modules/ajv/lib/compile/jtd/serialize.ts ADDED
@@ -0,0 +1,266 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import type Ajv from "../../core"
2
+ import type {SchemaObject} from "../../types"
3
+ import {jtdForms, JTDForm, SchemaObjectMap} from "./types"
4
+ import {SchemaEnv, getCompilingSchema} from ".."
5
+ import {_, str, and, getProperty, CodeGen, Code, Name} from "../codegen"
6
+ import MissingRefError from "../ref_error"
7
+ import N from "../names"
8
+ import {isOwnProperty} from "../../vocabularies/code"
9
+ import {hasRef} from "../../vocabularies/jtd/ref"
10
+ import {useFunc} from "../util"
11
+ import quote from "../../runtime/quote"
12
+
13
+ const genSerialize: {[F in JTDForm]: (cxt: SerializeCxt) => void} = {
14
+ elements: serializeElements,
15
+ values: serializeValues,
16
+ discriminator: serializeDiscriminator,
17
+ properties: serializeProperties,
18
+ optionalProperties: serializeProperties,
19
+ enum: serializeString,
20
+ type: serializeType,
21
+ ref: serializeRef,
22
+ }
23
+
24
+ interface SerializeCxt {
25
+ readonly gen: CodeGen
26
+ readonly self: Ajv // current Ajv instance
27
+ readonly schemaEnv: SchemaEnv
28
+ readonly definitions: SchemaObjectMap
29
+ schema: SchemaObject
30
+ data: Code
31
+ }
32
+
33
+ export default function compileSerializer(
34
+ this: Ajv,
35
+ sch: SchemaEnv,
36
+ definitions: SchemaObjectMap
37
+ ): SchemaEnv {
38
+ const _sch = getCompilingSchema.call(this, sch)
39
+ if (_sch) return _sch
40
+ const {es5, lines} = this.opts.code
41
+ const {ownProperties} = this.opts
42
+ const gen = new CodeGen(this.scope, {es5, lines, ownProperties})
43
+ const serializeName = gen.scopeName("serialize")
44
+ const cxt: SerializeCxt = {
45
+ self: this,
46
+ gen,
47
+ schema: sch.schema as SchemaObject,
48
+ schemaEnv: sch,
49
+ definitions,
50
+ data: N.data,
51
+ }
52
+
53
+ let sourceCode: string | undefined
54
+ try {
55
+ this._compilations.add(sch)
56
+ sch.serializeName = serializeName
57
+ gen.func(serializeName, N.data, false, () => {
58
+ gen.let(N.json, str``)
59
+ serializeCode(cxt)
60
+ gen.return(N.json)
61
+ })
62
+ gen.optimize(this.opts.code.optimize)
63
+ const serializeFuncCode = gen.toString()
64
+ sourceCode = `${gen.scopeRefs(N.scope)}return ${serializeFuncCode}`
65
+ const makeSerialize = new Function(`${N.scope}`, sourceCode)
66
+ const serialize: (data: unknown) => string = makeSerialize(this.scope.get())
67
+ this.scope.value(serializeName, {ref: serialize})
68
+ sch.serialize = serialize
69
+ } catch (e) {
70
+ if (sourceCode) this.logger.error("Error compiling serializer, function code:", sourceCode)
71
+ delete sch.serialize
72
+ delete sch.serializeName
73
+ throw e
74
+ } finally {
75
+ this._compilations.delete(sch)
76
+ }
77
+ return sch
78
+ }
79
+
80
+ function serializeCode(cxt: SerializeCxt): void {
81
+ let form: JTDForm | undefined
82
+ for (const key of jtdForms) {
83
+ if (key in cxt.schema) {
84
+ form = key
85
+ break
86
+ }
87
+ }
88
+ serializeNullable(cxt, form ? genSerialize[form] : serializeEmpty)
89
+ }
90
+
91
+ function serializeNullable(cxt: SerializeCxt, serializeForm: (_cxt: SerializeCxt) => void): void {
92
+ const {gen, schema, data} = cxt
93
+ if (!schema.nullable) return serializeForm(cxt)
94
+ gen.if(
95
+ _`${data} === undefined || ${data} === null`,
96
+ () => gen.add(N.json, _`"null"`),
97
+ () => serializeForm(cxt)
98
+ )
99
+ }
100
+
101
+ function serializeElements(cxt: SerializeCxt): void {
102
+ const {gen, schema, data} = cxt
103
+ gen.add(N.json, str`[`)
104
+ const first = gen.let("first", true)
105
+ gen.forOf("el", data, (el) => {
106
+ addComma(cxt, first)
107
+ serializeCode({...cxt, schema: schema.elements, data: el})
108
+ })
109
+ gen.add(N.json, str`]`)
110
+ }
111
+
112
+ function serializeValues(cxt: SerializeCxt): void {
113
+ const {gen, schema, data} = cxt
114
+ gen.add(N.json, str`{`)
115
+ const first = gen.let("first", true)
116
+ gen.forIn("key", data, (key) => serializeKeyValue(cxt, key, schema.values, first))
117
+ gen.add(N.json, str`}`)
118
+ }
119
+
120
+ function serializeKeyValue(cxt: SerializeCxt, key: Name, schema: SchemaObject, first?: Name): void {
121
+ const {gen, data} = cxt
122
+ addComma(cxt, first)
123
+ serializeString({...cxt, data: key})
124
+ gen.add(N.json, str`:`)
125
+ const value = gen.const("value", _`${data}${getProperty(key)}`)
126
+ serializeCode({...cxt, schema, data: value})
127
+ }
128
+
129
+ function serializeDiscriminator(cxt: SerializeCxt): void {
130
+ const {gen, schema, data} = cxt
131
+ const {discriminator} = schema
132
+ gen.add(N.json, str`{${JSON.stringify(discriminator)}:`)
133
+ const tag = gen.const("tag", _`${data}${getProperty(discriminator)}`)
134
+ serializeString({...cxt, data: tag})
135
+ gen.if(false)
136
+ for (const tagValue in schema.mapping) {
137
+ gen.elseIf(_`${tag} === ${tagValue}`)
138
+ const sch = schema.mapping[tagValue]
139
+ serializeSchemaProperties({...cxt, schema: sch}, discriminator)
140
+ }
141
+ gen.endIf()
142
+ gen.add(N.json, str`}`)
143
+ }
144
+
145
+ function serializeProperties(cxt: SerializeCxt): void {
146
+ const {gen} = cxt
147
+ gen.add(N.json, str`{`)
148
+ serializeSchemaProperties(cxt)
149
+ gen.add(N.json, str`}`)
150
+ }
151
+
152
+ function serializeSchemaProperties(cxt: SerializeCxt, discriminator?: string): void {
153
+ const {gen, schema, data} = cxt
154
+ const {properties, optionalProperties} = schema
155
+ const props = keys(properties)
156
+ const optProps = keys(optionalProperties)
157
+ const allProps = allProperties(props.concat(optProps))
158
+ let first = !discriminator
159
+ let firstProp: Name | undefined
160
+
161
+ for (const key of props) {
162
+ if (first) first = false
163
+ else gen.add(N.json, str`,`)
164
+ serializeProperty(key, properties[key], keyValue(key))
165
+ }
166
+ if (first) firstProp = gen.let("first", true)
167
+ for (const key of optProps) {
168
+ const value = keyValue(key)
169
+ gen.if(and(_`${value} !== undefined`, isOwnProperty(gen, data, key)), () => {
170
+ addComma(cxt, firstProp)
171
+ serializeProperty(key, optionalProperties[key], value)
172
+ })
173
+ }
174
+ if (schema.additionalProperties) {
175
+ gen.forIn("key", data, (key) =>
176
+ gen.if(isAdditional(key, allProps), () => serializeKeyValue(cxt, key, {}, firstProp))
177
+ )
178
+ }
179
+
180
+ function keys(ps?: SchemaObjectMap): string[] {
181
+ return ps ? Object.keys(ps) : []
182
+ }
183
+
184
+ function allProperties(ps: string[]): string[] {
185
+ if (discriminator) ps.push(discriminator)
186
+ if (new Set(ps).size !== ps.length) {
187
+ throw new Error("JTD: properties/optionalProperties/disciminator overlap")
188
+ }
189
+ return ps
190
+ }
191
+
192
+ function keyValue(key: string): Name {
193
+ return gen.const("value", _`${data}${getProperty(key)}`)
194
+ }
195
+
196
+ function serializeProperty(key: string, propSchema: SchemaObject, value: Name): void {
197
+ gen.add(N.json, str`${JSON.stringify(key)}:`)
198
+ serializeCode({...cxt, schema: propSchema, data: value})
199
+ }
200
+
201
+ function isAdditional(key: Name, ps: string[]): Code | true {
202
+ return ps.length ? and(...ps.map((p) => _`${key} !== ${p}`)) : true
203
+ }
204
+ }
205
+
206
+ function serializeType(cxt: SerializeCxt): void {
207
+ const {gen, schema, data} = cxt
208
+ switch (schema.type) {
209
+ case "boolean":
210
+ gen.add(N.json, _`${data} ? "true" : "false"`)
211
+ break
212
+ case "string":
213
+ serializeString(cxt)
214
+ break
215
+ case "timestamp":
216
+ gen.if(
217
+ _`${data} instanceof Date`,
218
+ () => gen.add(N.json, _`'"' + ${data}.toISOString() + '"'`),
219
+ () => serializeString(cxt)
220
+ )
221
+ break
222
+ default:
223
+ serializeNumber(cxt)
224
+ }
225
+ }
226
+
227
+ function serializeString({gen, data}: SerializeCxt): void {
228
+ gen.add(N.json, _`${useFunc(gen, quote)}(${data})`)
229
+ }
230
+
231
+ function serializeNumber({gen, data}: SerializeCxt): void {
232
+ gen.add(N.json, _`"" + ${data}`)
233
+ }
234
+
235
+ function serializeRef(cxt: SerializeCxt): void {
236
+ const {gen, self, data, definitions, schema, schemaEnv} = cxt
237
+ const {ref} = schema
238
+ const refSchema = definitions[ref]
239
+ if (!refSchema) throw new MissingRefError(self.opts.uriResolver, "", ref, `No definition ${ref}`)
240
+ if (!hasRef(refSchema)) return serializeCode({...cxt, schema: refSchema})
241
+ const {root} = schemaEnv
242
+ const sch = compileSerializer.call(self, new SchemaEnv({schema: refSchema, root}), definitions)
243
+ gen.add(N.json, _`${getSerialize(gen, sch)}(${data})`)
244
+ }
245
+
246
+ function getSerialize(gen: CodeGen, sch: SchemaEnv): Code {
247
+ return sch.serialize
248
+ ? gen.scopeValue("serialize", {ref: sch.serialize})
249
+ : _`${gen.scopeValue("wrapper", {ref: sch})}.serialize`
250
+ }
251
+
252
+ function serializeEmpty({gen, data}: SerializeCxt): void {
253
+ gen.add(N.json, _`JSON.stringify(${data})`)
254
+ }
255
+
256
+ function addComma({gen}: SerializeCxt, first?: Name): void {
257
+ if (first) {
258
+ gen.if(
259
+ first,
260
+ () => gen.assign(first, false),
261
+ () => gen.add(N.json, str`,`)
262
+ )
263
+ } else {
264
+ gen.add(N.json, str`,`)
265
+ }
266
+ }
platform/aiml/elizabeth/e-1-first_session/claude-code-router/node_modules/ajv/lib/compile/jtd/types.ts ADDED
@@ -0,0 +1,16 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import type {SchemaObject} from "../../types"
2
+
3
+ export type SchemaObjectMap = {[Ref in string]?: SchemaObject}
4
+
5
+ export const jtdForms = [
6
+ "elements",
7
+ "values",
8
+ "discriminator",
9
+ "properties",
10
+ "optionalProperties",
11
+ "enum",
12
+ "type",
13
+ "ref",
14
+ ] as const
15
+
16
+ export type JTDForm = (typeof jtdForms)[number]
platform/aiml/elizabeth/e-1-first_session/claude-code-router/node_modules/ajv/lib/compile/ref_error.ts ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import {resolveUrl, normalizeId, getFullPath} from "./resolve"
2
+ import type {UriResolver} from "../types"
3
+
4
+ export default class MissingRefError extends Error {
5
+ readonly missingRef: string
6
+ readonly missingSchema: string
7
+
8
+ constructor(resolver: UriResolver, baseId: string, ref: string, msg?: string) {
9
+ super(msg || `can't resolve reference ${ref} from id ${baseId}`)
10
+ this.missingRef = resolveUrl(resolver, baseId, ref)
11
+ this.missingSchema = normalizeId(getFullPath(resolver, this.missingRef))
12
+ }
13
+ }
platform/aiml/elizabeth/e-1-first_session/claude-code-router/node_modules/ajv/lib/compile/resolve.ts ADDED
@@ -0,0 +1,149 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import type {AnySchema, AnySchemaObject, UriResolver} from "../types"
2
+ import type Ajv from "../ajv"
3
+ import type {URIComponent} from "fast-uri"
4
+ import {eachItem} from "./util"
5
+ import * as equal from "fast-deep-equal"
6
+ import * as traverse from "json-schema-traverse"
7
+
8
+ // the hash of local references inside the schema (created by getSchemaRefs), used for inline resolution
9
+ export type LocalRefs = {[Ref in string]?: AnySchemaObject}
10
+
11
+ // TODO refactor to use keyword definitions
12
+ const SIMPLE_INLINED = new Set([
13
+ "type",
14
+ "format",
15
+ "pattern",
16
+ "maxLength",
17
+ "minLength",
18
+ "maxProperties",
19
+ "minProperties",
20
+ "maxItems",
21
+ "minItems",
22
+ "maximum",
23
+ "minimum",
24
+ "uniqueItems",
25
+ "multipleOf",
26
+ "required",
27
+ "enum",
28
+ "const",
29
+ ])
30
+
31
+ export function inlineRef(schema: AnySchema, limit: boolean | number = true): boolean {
32
+ if (typeof schema == "boolean") return true
33
+ if (limit === true) return !hasRef(schema)
34
+ if (!limit) return false
35
+ return countKeys(schema) <= limit
36
+ }
37
+
38
+ const REF_KEYWORDS = new Set([
39
+ "$ref",
40
+ "$recursiveRef",
41
+ "$recursiveAnchor",
42
+ "$dynamicRef",
43
+ "$dynamicAnchor",
44
+ ])
45
+
46
+ function hasRef(schema: AnySchemaObject): boolean {
47
+ for (const key in schema) {
48
+ if (REF_KEYWORDS.has(key)) return true
49
+ const sch = schema[key]
50
+ if (Array.isArray(sch) && sch.some(hasRef)) return true
51
+ if (typeof sch == "object" && hasRef(sch)) return true
52
+ }
53
+ return false
54
+ }
55
+
56
+ function countKeys(schema: AnySchemaObject): number {
57
+ let count = 0
58
+ for (const key in schema) {
59
+ if (key === "$ref") return Infinity
60
+ count++
61
+ if (SIMPLE_INLINED.has(key)) continue
62
+ if (typeof schema[key] == "object") {
63
+ eachItem(schema[key], (sch) => (count += countKeys(sch)))
64
+ }
65
+ if (count === Infinity) return Infinity
66
+ }
67
+ return count
68
+ }
69
+
70
+ export function getFullPath(resolver: UriResolver, id = "", normalize?: boolean): string {
71
+ if (normalize !== false) id = normalizeId(id)
72
+ const p = resolver.parse(id)
73
+ return _getFullPath(resolver, p)
74
+ }
75
+
76
+ export function _getFullPath(resolver: UriResolver, p: URIComponent): string {
77
+ const serialized = resolver.serialize(p)
78
+ return serialized.split("#")[0] + "#"
79
+ }
80
+
81
+ const TRAILING_SLASH_HASH = /#\/?$/
82
+ export function normalizeId(id: string | undefined): string {
83
+ return id ? id.replace(TRAILING_SLASH_HASH, "") : ""
84
+ }
85
+
86
+ export function resolveUrl(resolver: UriResolver, baseId: string, id: string): string {
87
+ id = normalizeId(id)
88
+ return resolver.resolve(baseId, id)
89
+ }
90
+
91
+ const ANCHOR = /^[a-z_][-a-z0-9._]*$/i
92
+
93
+ export function getSchemaRefs(this: Ajv, schema: AnySchema, baseId: string): LocalRefs {
94
+ if (typeof schema == "boolean") return {}
95
+ const {schemaId, uriResolver} = this.opts
96
+ const schId = normalizeId(schema[schemaId] || baseId)
97
+ const baseIds: {[JsonPtr in string]?: string} = {"": schId}
98
+ const pathPrefix = getFullPath(uriResolver, schId, false)
99
+ const localRefs: LocalRefs = {}
100
+ const schemaRefs: Set<string> = new Set()
101
+
102
+ traverse(schema, {allKeys: true}, (sch, jsonPtr, _, parentJsonPtr) => {
103
+ if (parentJsonPtr === undefined) return
104
+ const fullPath = pathPrefix + jsonPtr
105
+ let innerBaseId = baseIds[parentJsonPtr]
106
+ if (typeof sch[schemaId] == "string") innerBaseId = addRef.call(this, sch[schemaId])
107
+ addAnchor.call(this, sch.$anchor)
108
+ addAnchor.call(this, sch.$dynamicAnchor)
109
+ baseIds[jsonPtr] = innerBaseId
110
+
111
+ function addRef(this: Ajv, ref: string): string {
112
+ // eslint-disable-next-line @typescript-eslint/unbound-method
113
+ const _resolve = this.opts.uriResolver.resolve
114
+ ref = normalizeId(innerBaseId ? _resolve(innerBaseId, ref) : ref)
115
+ if (schemaRefs.has(ref)) throw ambiguos(ref)
116
+ schemaRefs.add(ref)
117
+ let schOrRef = this.refs[ref]
118
+ if (typeof schOrRef == "string") schOrRef = this.refs[schOrRef]
119
+ if (typeof schOrRef == "object") {
120
+ checkAmbiguosRef(sch, schOrRef.schema, ref)
121
+ } else if (ref !== normalizeId(fullPath)) {
122
+ if (ref[0] === "#") {
123
+ checkAmbiguosRef(sch, localRefs[ref], ref)
124
+ localRefs[ref] = sch
125
+ } else {
126
+ this.refs[ref] = fullPath
127
+ }
128
+ }
129
+ return ref
130
+ }
131
+
132
+ function addAnchor(this: Ajv, anchor: unknown): void {
133
+ if (typeof anchor == "string") {
134
+ if (!ANCHOR.test(anchor)) throw new Error(`invalid anchor "${anchor}"`)
135
+ addRef.call(this, `#${anchor}`)
136
+ }
137
+ }
138
+ })
139
+
140
+ return localRefs
141
+
142
+ function checkAmbiguosRef(sch1: AnySchema, sch2: AnySchema | undefined, ref: string): void {
143
+ if (sch2 !== undefined && !equal(sch1, sch2)) throw ambiguos(ref)
144
+ }
145
+
146
+ function ambiguos(ref: string): Error {
147
+ return new Error(`reference "${ref}" resolves to more than one schema`)
148
+ }
149
+ }
platform/aiml/elizabeth/e-1-first_session/claude-code-router/node_modules/ajv/lib/compile/validate/applicability.ts ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import type {AnySchemaObject} from "../../types"
2
+ import type {SchemaObjCxt} from ".."
3
+ import type {JSONType, RuleGroup, Rule} from "../rules"
4
+
5
+ export function schemaHasRulesForType(
6
+ {schema, self}: SchemaObjCxt,
7
+ type: JSONType
8
+ ): boolean | undefined {
9
+ const group = self.RULES.types[type]
10
+ return group && group !== true && shouldUseGroup(schema, group)
11
+ }
12
+
13
+ export function shouldUseGroup(schema: AnySchemaObject, group: RuleGroup): boolean {
14
+ return group.rules.some((rule) => shouldUseRule(schema, rule))
15
+ }
16
+
17
+ export function shouldUseRule(schema: AnySchemaObject, rule: Rule): boolean | undefined {
18
+ return (
19
+ schema[rule.keyword] !== undefined ||
20
+ rule.definition.implements?.some((kwd) => schema[kwd] !== undefined)
21
+ )
22
+ }
platform/aiml/elizabeth/e-1-first_session/claude-code-router/node_modules/ajv/lib/compile/validate/boolSchema.ts ADDED
@@ -0,0 +1,47 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import type {KeywordErrorDefinition, KeywordErrorCxt} from "../../types"
2
+ import type {SchemaCxt} from ".."
3
+ import {reportError} from "../errors"
4
+ import {_, Name} from "../codegen"
5
+ import N from "../names"
6
+
7
+ const boolError: KeywordErrorDefinition = {
8
+ message: "boolean schema is false",
9
+ }
10
+
11
+ export function topBoolOrEmptySchema(it: SchemaCxt): void {
12
+ const {gen, schema, validateName} = it
13
+ if (schema === false) {
14
+ falseSchemaError(it, false)
15
+ } else if (typeof schema == "object" && schema.$async === true) {
16
+ gen.return(N.data)
17
+ } else {
18
+ gen.assign(_`${validateName}.errors`, null)
19
+ gen.return(true)
20
+ }
21
+ }
22
+
23
+ export function boolOrEmptySchema(it: SchemaCxt, valid: Name): void {
24
+ const {gen, schema} = it
25
+ if (schema === false) {
26
+ gen.var(valid, false) // TODO var
27
+ falseSchemaError(it)
28
+ } else {
29
+ gen.var(valid, true) // TODO var
30
+ }
31
+ }
32
+
33
+ function falseSchemaError(it: SchemaCxt, overrideAllErrors?: boolean): void {
34
+ const {gen, data} = it
35
+ // TODO maybe some other interface should be used for non-keyword validation errors...
36
+ const cxt: KeywordErrorCxt = {
37
+ gen,
38
+ keyword: "false schema",
39
+ data,
40
+ schema: false,
41
+ schemaCode: false,
42
+ schemaValue: false,
43
+ params: {},
44
+ it,
45
+ }
46
+ reportError(cxt, boolError, undefined, overrideAllErrors)
47
+ }
platform/aiml/elizabeth/e-1-first_session/claude-code-router/node_modules/ajv/lib/compile/validate/dataType.ts ADDED
@@ -0,0 +1,230 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import type {
2
+ KeywordErrorDefinition,
3
+ KeywordErrorCxt,
4
+ ErrorObject,
5
+ AnySchemaObject,
6
+ } from "../../types"
7
+ import type {SchemaObjCxt} from ".."
8
+ import {isJSONType, JSONType} from "../rules"
9
+ import {schemaHasRulesForType} from "./applicability"
10
+ import {reportError} from "../errors"
11
+ import {_, nil, and, not, operators, Code, Name} from "../codegen"
12
+ import {toHash, schemaRefOrVal} from "../util"
13
+
14
+ export enum DataType {
15
+ Correct,
16
+ Wrong,
17
+ }
18
+
19
+ export function getSchemaTypes(schema: AnySchemaObject): JSONType[] {
20
+ const types = getJSONTypes(schema.type)
21
+ const hasNull = types.includes("null")
22
+ if (hasNull) {
23
+ if (schema.nullable === false) throw new Error("type: null contradicts nullable: false")
24
+ } else {
25
+ if (!types.length && schema.nullable !== undefined) {
26
+ throw new Error('"nullable" cannot be used without "type"')
27
+ }
28
+ if (schema.nullable === true) types.push("null")
29
+ }
30
+ return types
31
+ }
32
+
33
+ // eslint-disable-next-line @typescript-eslint/no-redundant-type-constituents
34
+ export function getJSONTypes(ts: unknown | unknown[]): JSONType[] {
35
+ const types: unknown[] = Array.isArray(ts) ? ts : ts ? [ts] : []
36
+ if (types.every(isJSONType)) return types
37
+ throw new Error("type must be JSONType or JSONType[]: " + types.join(","))
38
+ }
39
+
40
+ export function coerceAndCheckDataType(it: SchemaObjCxt, types: JSONType[]): boolean {
41
+ const {gen, data, opts} = it
42
+ const coerceTo = coerceToTypes(types, opts.coerceTypes)
43
+ const checkTypes =
44
+ types.length > 0 &&
45
+ !(coerceTo.length === 0 && types.length === 1 && schemaHasRulesForType(it, types[0]))
46
+ if (checkTypes) {
47
+ const wrongType = checkDataTypes(types, data, opts.strictNumbers, DataType.Wrong)
48
+ gen.if(wrongType, () => {
49
+ if (coerceTo.length) coerceData(it, types, coerceTo)
50
+ else reportTypeError(it)
51
+ })
52
+ }
53
+ return checkTypes
54
+ }
55
+
56
+ const COERCIBLE: Set<JSONType> = new Set(["string", "number", "integer", "boolean", "null"])
57
+ function coerceToTypes(types: JSONType[], coerceTypes?: boolean | "array"): JSONType[] {
58
+ return coerceTypes
59
+ ? types.filter((t) => COERCIBLE.has(t) || (coerceTypes === "array" && t === "array"))
60
+ : []
61
+ }
62
+
63
+ function coerceData(it: SchemaObjCxt, types: JSONType[], coerceTo: JSONType[]): void {
64
+ const {gen, data, opts} = it
65
+ const dataType = gen.let("dataType", _`typeof ${data}`)
66
+ const coerced = gen.let("coerced", _`undefined`)
67
+ if (opts.coerceTypes === "array") {
68
+ gen.if(_`${dataType} == 'object' && Array.isArray(${data}) && ${data}.length == 1`, () =>
69
+ gen
70
+ .assign(data, _`${data}[0]`)
71
+ .assign(dataType, _`typeof ${data}`)
72
+ .if(checkDataTypes(types, data, opts.strictNumbers), () => gen.assign(coerced, data))
73
+ )
74
+ }
75
+ gen.if(_`${coerced} !== undefined`)
76
+ for (const t of coerceTo) {
77
+ if (COERCIBLE.has(t) || (t === "array" && opts.coerceTypes === "array")) {
78
+ coerceSpecificType(t)
79
+ }
80
+ }
81
+ gen.else()
82
+ reportTypeError(it)
83
+ gen.endIf()
84
+
85
+ gen.if(_`${coerced} !== undefined`, () => {
86
+ gen.assign(data, coerced)
87
+ assignParentData(it, coerced)
88
+ })
89
+
90
+ function coerceSpecificType(t: string): void {
91
+ switch (t) {
92
+ case "string":
93
+ gen
94
+ .elseIf(_`${dataType} == "number" || ${dataType} == "boolean"`)
95
+ .assign(coerced, _`"" + ${data}`)
96
+ .elseIf(_`${data} === null`)
97
+ .assign(coerced, _`""`)
98
+ return
99
+ case "number":
100
+ gen
101
+ .elseIf(
102
+ _`${dataType} == "boolean" || ${data} === null
103
+ || (${dataType} == "string" && ${data} && ${data} == +${data})`
104
+ )
105
+ .assign(coerced, _`+${data}`)
106
+ return
107
+ case "integer":
108
+ gen
109
+ .elseIf(
110
+ _`${dataType} === "boolean" || ${data} === null
111
+ || (${dataType} === "string" && ${data} && ${data} == +${data} && !(${data} % 1))`
112
+ )
113
+ .assign(coerced, _`+${data}`)
114
+ return
115
+ case "boolean":
116
+ gen
117
+ .elseIf(_`${data} === "false" || ${data} === 0 || ${data} === null`)
118
+ .assign(coerced, false)
119
+ .elseIf(_`${data} === "true" || ${data} === 1`)
120
+ .assign(coerced, true)
121
+ return
122
+ case "null":
123
+ gen.elseIf(_`${data} === "" || ${data} === 0 || ${data} === false`)
124
+ gen.assign(coerced, null)
125
+ return
126
+
127
+ case "array":
128
+ gen
129
+ .elseIf(
130
+ _`${dataType} === "string" || ${dataType} === "number"
131
+ || ${dataType} === "boolean" || ${data} === null`
132
+ )
133
+ .assign(coerced, _`[${data}]`)
134
+ }
135
+ }
136
+ }
137
+
138
+ function assignParentData({gen, parentData, parentDataProperty}: SchemaObjCxt, expr: Name): void {
139
+ // TODO use gen.property
140
+ gen.if(_`${parentData} !== undefined`, () =>
141
+ gen.assign(_`${parentData}[${parentDataProperty}]`, expr)
142
+ )
143
+ }
144
+
145
+ export function checkDataType(
146
+ dataType: JSONType,
147
+ data: Name,
148
+ strictNums?: boolean | "log",
149
+ correct = DataType.Correct
150
+ ): Code {
151
+ const EQ = correct === DataType.Correct ? operators.EQ : operators.NEQ
152
+ let cond: Code
153
+ switch (dataType) {
154
+ case "null":
155
+ return _`${data} ${EQ} null`
156
+ case "array":
157
+ cond = _`Array.isArray(${data})`
158
+ break
159
+ case "object":
160
+ cond = _`${data} && typeof ${data} == "object" && !Array.isArray(${data})`
161
+ break
162
+ case "integer":
163
+ cond = numCond(_`!(${data} % 1) && !isNaN(${data})`)
164
+ break
165
+ case "number":
166
+ cond = numCond()
167
+ break
168
+ default:
169
+ return _`typeof ${data} ${EQ} ${dataType}`
170
+ }
171
+ return correct === DataType.Correct ? cond : not(cond)
172
+
173
+ function numCond(_cond: Code = nil): Code {
174
+ return and(_`typeof ${data} == "number"`, _cond, strictNums ? _`isFinite(${data})` : nil)
175
+ }
176
+ }
177
+
178
+ export function checkDataTypes(
179
+ dataTypes: JSONType[],
180
+ data: Name,
181
+ strictNums?: boolean | "log",
182
+ correct?: DataType
183
+ ): Code {
184
+ if (dataTypes.length === 1) {
185
+ return checkDataType(dataTypes[0], data, strictNums, correct)
186
+ }
187
+ let cond: Code
188
+ const types = toHash(dataTypes)
189
+ if (types.array && types.object) {
190
+ const notObj = _`typeof ${data} != "object"`
191
+ cond = types.null ? notObj : _`!${data} || ${notObj}`
192
+ delete types.null
193
+ delete types.array
194
+ delete types.object
195
+ } else {
196
+ cond = nil
197
+ }
198
+ if (types.number) delete types.integer
199
+ for (const t in types) cond = and(cond, checkDataType(t as JSONType, data, strictNums, correct))
200
+ return cond
201
+ }
202
+
203
+ export type TypeError = ErrorObject<"type", {type: string}>
204
+
205
+ const typeError: KeywordErrorDefinition = {
206
+ message: ({schema}) => `must be ${schema}`,
207
+ params: ({schema, schemaValue}) =>
208
+ typeof schema == "string" ? _`{type: ${schema}}` : _`{type: ${schemaValue}}`,
209
+ }
210
+
211
+ export function reportTypeError(it: SchemaObjCxt): void {
212
+ const cxt = getTypeErrorContext(it)
213
+ reportError(cxt, typeError)
214
+ }
215
+
216
+ function getTypeErrorContext(it: SchemaObjCxt): KeywordErrorCxt {
217
+ const {gen, data, schema} = it
218
+ const schemaCode = schemaRefOrVal(it, schema, "type")
219
+ return {
220
+ gen,
221
+ keyword: "type",
222
+ data,
223
+ schema: schema.type,
224
+ schemaCode,
225
+ schemaValue: schemaCode,
226
+ parentSchema: schema,
227
+ params: {},
228
+ it,
229
+ }
230
+ }
platform/aiml/elizabeth/e-1-first_session/claude-code-router/node_modules/ajv/lib/compile/validate/defaults.ts ADDED
@@ -0,0 +1,32 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import type {SchemaObjCxt} from ".."
2
+ import {_, getProperty, stringify} from "../codegen"
3
+ import {checkStrictMode} from "../util"
4
+
5
+ export function assignDefaults(it: SchemaObjCxt, ty?: string): void {
6
+ const {properties, items} = it.schema
7
+ if (ty === "object" && properties) {
8
+ for (const key in properties) {
9
+ assignDefault(it, key, properties[key].default)
10
+ }
11
+ } else if (ty === "array" && Array.isArray(items)) {
12
+ items.forEach((sch, i: number) => assignDefault(it, i, sch.default))
13
+ }
14
+ }
15
+
16
+ function assignDefault(it: SchemaObjCxt, prop: string | number, defaultValue: unknown): void {
17
+ const {gen, compositeRule, data, opts} = it
18
+ if (defaultValue === undefined) return
19
+ const childData = _`${data}${getProperty(prop)}`
20
+ if (compositeRule) {
21
+ checkStrictMode(it, `default is ignored for: ${childData}`)
22
+ return
23
+ }
24
+
25
+ let condition = _`${childData} === undefined`
26
+ if (opts.useDefaults === "empty") {
27
+ condition = _`${condition} || ${childData} === null || ${childData} === ""`
28
+ }
29
+ // `${childData} === undefined` +
30
+ // (opts.useDefaults === "empty" ? ` || ${childData} === null || ${childData} === ""` : "")
31
+ gen.if(condition, _`${childData} = ${stringify(defaultValue)}`)
32
+ }
platform/aiml/elizabeth/e-1-first_session/claude-code-router/node_modules/ajv/lib/compile/validate/index.ts ADDED
@@ -0,0 +1,582 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import type {
2
+ AddedKeywordDefinition,
3
+ AnySchema,
4
+ AnySchemaObject,
5
+ KeywordErrorCxt,
6
+ KeywordCxtParams,
7
+ } from "../../types"
8
+ import type {SchemaCxt, SchemaObjCxt} from ".."
9
+ import type {InstanceOptions} from "../../core"
10
+ import {boolOrEmptySchema, topBoolOrEmptySchema} from "./boolSchema"
11
+ import {coerceAndCheckDataType, getSchemaTypes} from "./dataType"
12
+ import {shouldUseGroup, shouldUseRule} from "./applicability"
13
+ import {checkDataType, checkDataTypes, reportTypeError, DataType} from "./dataType"
14
+ import {assignDefaults} from "./defaults"
15
+ import {funcKeywordCode, macroKeywordCode, validateKeywordUsage, validSchemaType} from "./keyword"
16
+ import {getSubschema, extendSubschemaData, SubschemaArgs, extendSubschemaMode} from "./subschema"
17
+ import {_, nil, str, or, not, getProperty, Block, Code, Name, CodeGen} from "../codegen"
18
+ import N from "../names"
19
+ import {resolveUrl} from "../resolve"
20
+ import {
21
+ schemaRefOrVal,
22
+ schemaHasRulesButRef,
23
+ checkUnknownRules,
24
+ checkStrictMode,
25
+ unescapeJsonPointer,
26
+ mergeEvaluated,
27
+ } from "../util"
28
+ import type {JSONType, Rule, RuleGroup} from "../rules"
29
+ import {
30
+ ErrorPaths,
31
+ reportError,
32
+ reportExtraError,
33
+ resetErrorsCount,
34
+ keyword$DataError,
35
+ } from "../errors"
36
+
37
+ // schema compilation - generates validation function, subschemaCode (below) is used for subschemas
38
+ export function validateFunctionCode(it: SchemaCxt): void {
39
+ if (isSchemaObj(it)) {
40
+ checkKeywords(it)
41
+ if (schemaCxtHasRules(it)) {
42
+ topSchemaObjCode(it)
43
+ return
44
+ }
45
+ }
46
+ validateFunction(it, () => topBoolOrEmptySchema(it))
47
+ }
48
+
49
+ function validateFunction(
50
+ {gen, validateName, schema, schemaEnv, opts}: SchemaCxt,
51
+ body: Block
52
+ ): void {
53
+ if (opts.code.es5) {
54
+ gen.func(validateName, _`${N.data}, ${N.valCxt}`, schemaEnv.$async, () => {
55
+ gen.code(_`"use strict"; ${funcSourceUrl(schema, opts)}`)
56
+ destructureValCxtES5(gen, opts)
57
+ gen.code(body)
58
+ })
59
+ } else {
60
+ gen.func(validateName, _`${N.data}, ${destructureValCxt(opts)}`, schemaEnv.$async, () =>
61
+ gen.code(funcSourceUrl(schema, opts)).code(body)
62
+ )
63
+ }
64
+ }
65
+
66
+ function destructureValCxt(opts: InstanceOptions): Code {
67
+ return _`{${N.instancePath}="", ${N.parentData}, ${N.parentDataProperty}, ${N.rootData}=${
68
+ N.data
69
+ }${opts.dynamicRef ? _`, ${N.dynamicAnchors}={}` : nil}}={}`
70
+ }
71
+
72
+ function destructureValCxtES5(gen: CodeGen, opts: InstanceOptions): void {
73
+ gen.if(
74
+ N.valCxt,
75
+ () => {
76
+ gen.var(N.instancePath, _`${N.valCxt}.${N.instancePath}`)
77
+ gen.var(N.parentData, _`${N.valCxt}.${N.parentData}`)
78
+ gen.var(N.parentDataProperty, _`${N.valCxt}.${N.parentDataProperty}`)
79
+ gen.var(N.rootData, _`${N.valCxt}.${N.rootData}`)
80
+ if (opts.dynamicRef) gen.var(N.dynamicAnchors, _`${N.valCxt}.${N.dynamicAnchors}`)
81
+ },
82
+ () => {
83
+ gen.var(N.instancePath, _`""`)
84
+ gen.var(N.parentData, _`undefined`)
85
+ gen.var(N.parentDataProperty, _`undefined`)
86
+ gen.var(N.rootData, N.data)
87
+ if (opts.dynamicRef) gen.var(N.dynamicAnchors, _`{}`)
88
+ }
89
+ )
90
+ }
91
+
92
+ function topSchemaObjCode(it: SchemaObjCxt): void {
93
+ const {schema, opts, gen} = it
94
+ validateFunction(it, () => {
95
+ if (opts.$comment && schema.$comment) commentKeyword(it)
96
+ checkNoDefault(it)
97
+ gen.let(N.vErrors, null)
98
+ gen.let(N.errors, 0)
99
+ if (opts.unevaluated) resetEvaluated(it)
100
+ typeAndKeywords(it)
101
+ returnResults(it)
102
+ })
103
+ return
104
+ }
105
+
106
+ function resetEvaluated(it: SchemaObjCxt): void {
107
+ // TODO maybe some hook to execute it in the end to check whether props/items are Name, as in assignEvaluated
108
+ const {gen, validateName} = it
109
+ it.evaluated = gen.const("evaluated", _`${validateName}.evaluated`)
110
+ gen.if(_`${it.evaluated}.dynamicProps`, () => gen.assign(_`${it.evaluated}.props`, _`undefined`))
111
+ gen.if(_`${it.evaluated}.dynamicItems`, () => gen.assign(_`${it.evaluated}.items`, _`undefined`))
112
+ }
113
+
114
+ function funcSourceUrl(schema: AnySchema, opts: InstanceOptions): Code {
115
+ const schId = typeof schema == "object" && schema[opts.schemaId]
116
+ return schId && (opts.code.source || opts.code.process) ? _`/*# sourceURL=${schId} */` : nil
117
+ }
118
+
119
+ // schema compilation - this function is used recursively to generate code for sub-schemas
120
+ function subschemaCode(it: SchemaCxt, valid: Name): void {
121
+ if (isSchemaObj(it)) {
122
+ checkKeywords(it)
123
+ if (schemaCxtHasRules(it)) {
124
+ subSchemaObjCode(it, valid)
125
+ return
126
+ }
127
+ }
128
+ boolOrEmptySchema(it, valid)
129
+ }
130
+
131
+ function schemaCxtHasRules({schema, self}: SchemaCxt): boolean {
132
+ if (typeof schema == "boolean") return !schema
133
+ for (const key in schema) if (self.RULES.all[key]) return true
134
+ return false
135
+ }
136
+
137
+ function isSchemaObj(it: SchemaCxt): it is SchemaObjCxt {
138
+ return typeof it.schema != "boolean"
139
+ }
140
+
141
+ function subSchemaObjCode(it: SchemaObjCxt, valid: Name): void {
142
+ const {schema, gen, opts} = it
143
+ if (opts.$comment && schema.$comment) commentKeyword(it)
144
+ updateContext(it)
145
+ checkAsyncSchema(it)
146
+ const errsCount = gen.const("_errs", N.errors)
147
+ typeAndKeywords(it, errsCount)
148
+ // TODO var
149
+ gen.var(valid, _`${errsCount} === ${N.errors}`)
150
+ }
151
+
152
+ function checkKeywords(it: SchemaObjCxt): void {
153
+ checkUnknownRules(it)
154
+ checkRefsAndKeywords(it)
155
+ }
156
+
157
+ function typeAndKeywords(it: SchemaObjCxt, errsCount?: Name): void {
158
+ if (it.opts.jtd) return schemaKeywords(it, [], false, errsCount)
159
+ const types = getSchemaTypes(it.schema)
160
+ const checkedTypes = coerceAndCheckDataType(it, types)
161
+ schemaKeywords(it, types, !checkedTypes, errsCount)
162
+ }
163
+
164
+ function checkRefsAndKeywords(it: SchemaObjCxt): void {
165
+ const {schema, errSchemaPath, opts, self} = it
166
+ if (schema.$ref && opts.ignoreKeywordsWithRef && schemaHasRulesButRef(schema, self.RULES)) {
167
+ self.logger.warn(`$ref: keywords ignored in schema at path "${errSchemaPath}"`)
168
+ }
169
+ }
170
+
171
+ function checkNoDefault(it: SchemaObjCxt): void {
172
+ const {schema, opts} = it
173
+ if (schema.default !== undefined && opts.useDefaults && opts.strictSchema) {
174
+ checkStrictMode(it, "default is ignored in the schema root")
175
+ }
176
+ }
177
+
178
+ function updateContext(it: SchemaObjCxt): void {
179
+ const schId = it.schema[it.opts.schemaId]
180
+ if (schId) it.baseId = resolveUrl(it.opts.uriResolver, it.baseId, schId)
181
+ }
182
+
183
+ function checkAsyncSchema(it: SchemaObjCxt): void {
184
+ if (it.schema.$async && !it.schemaEnv.$async) throw new Error("async schema in sync schema")
185
+ }
186
+
187
+ function commentKeyword({gen, schemaEnv, schema, errSchemaPath, opts}: SchemaObjCxt): void {
188
+ const msg = schema.$comment
189
+ if (opts.$comment === true) {
190
+ gen.code(_`${N.self}.logger.log(${msg})`)
191
+ } else if (typeof opts.$comment == "function") {
192
+ const schemaPath = str`${errSchemaPath}/$comment`
193
+ const rootName = gen.scopeValue("root", {ref: schemaEnv.root})
194
+ gen.code(_`${N.self}.opts.$comment(${msg}, ${schemaPath}, ${rootName}.schema)`)
195
+ }
196
+ }
197
+
198
+ function returnResults(it: SchemaCxt): void {
199
+ const {gen, schemaEnv, validateName, ValidationError, opts} = it
200
+ if (schemaEnv.$async) {
201
+ // TODO assign unevaluated
202
+ gen.if(
203
+ _`${N.errors} === 0`,
204
+ () => gen.return(N.data),
205
+ () => gen.throw(_`new ${ValidationError as Name}(${N.vErrors})`)
206
+ )
207
+ } else {
208
+ gen.assign(_`${validateName}.errors`, N.vErrors)
209
+ if (opts.unevaluated) assignEvaluated(it)
210
+ gen.return(_`${N.errors} === 0`)
211
+ }
212
+ }
213
+
214
+ function assignEvaluated({gen, evaluated, props, items}: SchemaCxt): void {
215
+ if (props instanceof Name) gen.assign(_`${evaluated}.props`, props)
216
+ if (items instanceof Name) gen.assign(_`${evaluated}.items`, items)
217
+ }
218
+
219
+ function schemaKeywords(
220
+ it: SchemaObjCxt,
221
+ types: JSONType[],
222
+ typeErrors: boolean,
223
+ errsCount?: Name
224
+ ): void {
225
+ const {gen, schema, data, allErrors, opts, self} = it
226
+ const {RULES} = self
227
+ if (schema.$ref && (opts.ignoreKeywordsWithRef || !schemaHasRulesButRef(schema, RULES))) {
228
+ gen.block(() => keywordCode(it, "$ref", (RULES.all.$ref as Rule).definition)) // TODO typecast
229
+ return
230
+ }
231
+ if (!opts.jtd) checkStrictTypes(it, types)
232
+ gen.block(() => {
233
+ for (const group of RULES.rules) groupKeywords(group)
234
+ groupKeywords(RULES.post)
235
+ })
236
+
237
+ function groupKeywords(group: RuleGroup): void {
238
+ if (!shouldUseGroup(schema, group)) return
239
+ if (group.type) {
240
+ gen.if(checkDataType(group.type, data, opts.strictNumbers))
241
+ iterateKeywords(it, group)
242
+ if (types.length === 1 && types[0] === group.type && typeErrors) {
243
+ gen.else()
244
+ reportTypeError(it)
245
+ }
246
+ gen.endIf()
247
+ } else {
248
+ iterateKeywords(it, group)
249
+ }
250
+ // TODO make it "ok" call?
251
+ if (!allErrors) gen.if(_`${N.errors} === ${errsCount || 0}`)
252
+ }
253
+ }
254
+
255
+ function iterateKeywords(it: SchemaObjCxt, group: RuleGroup): void {
256
+ const {
257
+ gen,
258
+ schema,
259
+ opts: {useDefaults},
260
+ } = it
261
+ if (useDefaults) assignDefaults(it, group.type)
262
+ gen.block(() => {
263
+ for (const rule of group.rules) {
264
+ if (shouldUseRule(schema, rule)) {
265
+ keywordCode(it, rule.keyword, rule.definition, group.type)
266
+ }
267
+ }
268
+ })
269
+ }
270
+
271
+ function checkStrictTypes(it: SchemaObjCxt, types: JSONType[]): void {
272
+ if (it.schemaEnv.meta || !it.opts.strictTypes) return
273
+ checkContextTypes(it, types)
274
+ if (!it.opts.allowUnionTypes) checkMultipleTypes(it, types)
275
+ checkKeywordTypes(it, it.dataTypes)
276
+ }
277
+
278
+ function checkContextTypes(it: SchemaObjCxt, types: JSONType[]): void {
279
+ if (!types.length) return
280
+ if (!it.dataTypes.length) {
281
+ it.dataTypes = types
282
+ return
283
+ }
284
+ types.forEach((t) => {
285
+ if (!includesType(it.dataTypes, t)) {
286
+ strictTypesError(it, `type "${t}" not allowed by context "${it.dataTypes.join(",")}"`)
287
+ }
288
+ })
289
+ narrowSchemaTypes(it, types)
290
+ }
291
+
292
+ function checkMultipleTypes(it: SchemaObjCxt, ts: JSONType[]): void {
293
+ if (ts.length > 1 && !(ts.length === 2 && ts.includes("null"))) {
294
+ strictTypesError(it, "use allowUnionTypes to allow union type keyword")
295
+ }
296
+ }
297
+
298
+ function checkKeywordTypes(it: SchemaObjCxt, ts: JSONType[]): void {
299
+ const rules = it.self.RULES.all
300
+ for (const keyword in rules) {
301
+ const rule = rules[keyword]
302
+ if (typeof rule == "object" && shouldUseRule(it.schema, rule)) {
303
+ const {type} = rule.definition
304
+ if (type.length && !type.some((t) => hasApplicableType(ts, t))) {
305
+ strictTypesError(it, `missing type "${type.join(",")}" for keyword "${keyword}"`)
306
+ }
307
+ }
308
+ }
309
+ }
310
+
311
+ function hasApplicableType(schTs: JSONType[], kwdT: JSONType): boolean {
312
+ return schTs.includes(kwdT) || (kwdT === "number" && schTs.includes("integer"))
313
+ }
314
+
315
+ function includesType(ts: JSONType[], t: JSONType): boolean {
316
+ return ts.includes(t) || (t === "integer" && ts.includes("number"))
317
+ }
318
+
319
+ function narrowSchemaTypes(it: SchemaObjCxt, withTypes: JSONType[]): void {
320
+ const ts: JSONType[] = []
321
+ for (const t of it.dataTypes) {
322
+ if (includesType(withTypes, t)) ts.push(t)
323
+ else if (withTypes.includes("integer") && t === "number") ts.push("integer")
324
+ }
325
+ it.dataTypes = ts
326
+ }
327
+
328
+ function strictTypesError(it: SchemaObjCxt, msg: string): void {
329
+ const schemaPath = it.schemaEnv.baseId + it.errSchemaPath
330
+ msg += ` at "${schemaPath}" (strictTypes)`
331
+ checkStrictMode(it, msg, it.opts.strictTypes)
332
+ }
333
+
334
+ export class KeywordCxt implements KeywordErrorCxt {
335
+ readonly gen: CodeGen
336
+ readonly allErrors?: boolean
337
+ readonly keyword: string
338
+ readonly data: Name // Name referencing the current level of the data instance
339
+ readonly $data?: string | false
340
+ schema: any // keyword value in the schema
341
+ readonly schemaValue: Code | number | boolean // Code reference to keyword schema value or primitive value
342
+ readonly schemaCode: Code | number | boolean // Code reference to resolved schema value (different if schema is $data)
343
+ readonly schemaType: JSONType[] // allowed type(s) of keyword value in the schema
344
+ readonly parentSchema: AnySchemaObject
345
+ readonly errsCount?: Name // Name reference to the number of validation errors collected before this keyword,
346
+ // requires option trackErrors in keyword definition
347
+ params: KeywordCxtParams // object to pass parameters to error messages from keyword code
348
+ readonly it: SchemaObjCxt // schema compilation context (schema is guaranteed to be an object, not boolean)
349
+ readonly def: AddedKeywordDefinition
350
+
351
+ constructor(it: SchemaObjCxt, def: AddedKeywordDefinition, keyword: string) {
352
+ validateKeywordUsage(it, def, keyword)
353
+ this.gen = it.gen
354
+ this.allErrors = it.allErrors
355
+ this.keyword = keyword
356
+ this.data = it.data
357
+ this.schema = it.schema[keyword]
358
+ this.$data = def.$data && it.opts.$data && this.schema && this.schema.$data
359
+ this.schemaValue = schemaRefOrVal(it, this.schema, keyword, this.$data)
360
+ this.schemaType = def.schemaType
361
+ this.parentSchema = it.schema
362
+ this.params = {}
363
+ this.it = it
364
+ this.def = def
365
+
366
+ if (this.$data) {
367
+ this.schemaCode = it.gen.const("vSchema", getData(this.$data, it))
368
+ } else {
369
+ this.schemaCode = this.schemaValue
370
+ if (!validSchemaType(this.schema, def.schemaType, def.allowUndefined)) {
371
+ throw new Error(`${keyword} value must be ${JSON.stringify(def.schemaType)}`)
372
+ }
373
+ }
374
+
375
+ if ("code" in def ? def.trackErrors : def.errors !== false) {
376
+ this.errsCount = it.gen.const("_errs", N.errors)
377
+ }
378
+ }
379
+
380
+ result(condition: Code, successAction?: () => void, failAction?: () => void): void {
381
+ this.failResult(not(condition), successAction, failAction)
382
+ }
383
+
384
+ failResult(condition: Code, successAction?: () => void, failAction?: () => void): void {
385
+ this.gen.if(condition)
386
+ if (failAction) failAction()
387
+ else this.error()
388
+ if (successAction) {
389
+ this.gen.else()
390
+ successAction()
391
+ if (this.allErrors) this.gen.endIf()
392
+ } else {
393
+ if (this.allErrors) this.gen.endIf()
394
+ else this.gen.else()
395
+ }
396
+ }
397
+
398
+ pass(condition: Code, failAction?: () => void): void {
399
+ this.failResult(not(condition), undefined, failAction)
400
+ }
401
+
402
+ fail(condition?: Code): void {
403
+ if (condition === undefined) {
404
+ this.error()
405
+ if (!this.allErrors) this.gen.if(false) // this branch will be removed by gen.optimize
406
+ return
407
+ }
408
+ this.gen.if(condition)
409
+ this.error()
410
+ if (this.allErrors) this.gen.endIf()
411
+ else this.gen.else()
412
+ }
413
+
414
+ fail$data(condition: Code): void {
415
+ if (!this.$data) return this.fail(condition)
416
+ const {schemaCode} = this
417
+ this.fail(_`${schemaCode} !== undefined && (${or(this.invalid$data(), condition)})`)
418
+ }
419
+
420
+ error(append?: boolean, errorParams?: KeywordCxtParams, errorPaths?: ErrorPaths): void {
421
+ if (errorParams) {
422
+ this.setParams(errorParams)
423
+ this._error(append, errorPaths)
424
+ this.setParams({})
425
+ return
426
+ }
427
+ this._error(append, errorPaths)
428
+ }
429
+
430
+ private _error(append?: boolean, errorPaths?: ErrorPaths): void {
431
+ ;(append ? reportExtraError : reportError)(this, this.def.error, errorPaths)
432
+ }
433
+
434
+ $dataError(): void {
435
+ reportError(this, this.def.$dataError || keyword$DataError)
436
+ }
437
+
438
+ reset(): void {
439
+ if (this.errsCount === undefined) throw new Error('add "trackErrors" to keyword definition')
440
+ resetErrorsCount(this.gen, this.errsCount)
441
+ }
442
+
443
+ ok(cond: Code | boolean): void {
444
+ if (!this.allErrors) this.gen.if(cond)
445
+ }
446
+
447
+ setParams(obj: KeywordCxtParams, assign?: true): void {
448
+ if (assign) Object.assign(this.params, obj)
449
+ else this.params = obj
450
+ }
451
+
452
+ block$data(valid: Name, codeBlock: () => void, $dataValid: Code = nil): void {
453
+ this.gen.block(() => {
454
+ this.check$data(valid, $dataValid)
455
+ codeBlock()
456
+ })
457
+ }
458
+
459
+ check$data(valid: Name = nil, $dataValid: Code = nil): void {
460
+ if (!this.$data) return
461
+ const {gen, schemaCode, schemaType, def} = this
462
+ gen.if(or(_`${schemaCode} === undefined`, $dataValid))
463
+ if (valid !== nil) gen.assign(valid, true)
464
+ if (schemaType.length || def.validateSchema) {
465
+ gen.elseIf(this.invalid$data())
466
+ this.$dataError()
467
+ if (valid !== nil) gen.assign(valid, false)
468
+ }
469
+ gen.else()
470
+ }
471
+
472
+ invalid$data(): Code {
473
+ const {gen, schemaCode, schemaType, def, it} = this
474
+ return or(wrong$DataType(), invalid$DataSchema())
475
+
476
+ function wrong$DataType(): Code {
477
+ if (schemaType.length) {
478
+ /* istanbul ignore if */
479
+ if (!(schemaCode instanceof Name)) throw new Error("ajv implementation error")
480
+ const st = Array.isArray(schemaType) ? schemaType : [schemaType]
481
+ return _`${checkDataTypes(st, schemaCode, it.opts.strictNumbers, DataType.Wrong)}`
482
+ }
483
+ return nil
484
+ }
485
+
486
+ function invalid$DataSchema(): Code {
487
+ if (def.validateSchema) {
488
+ const validateSchemaRef = gen.scopeValue("validate$data", {ref: def.validateSchema}) // TODO value.code for standalone
489
+ return _`!${validateSchemaRef}(${schemaCode})`
490
+ }
491
+ return nil
492
+ }
493
+ }
494
+
495
+ subschema(appl: SubschemaArgs, valid: Name): SchemaCxt {
496
+ const subschema = getSubschema(this.it, appl)
497
+ extendSubschemaData(subschema, this.it, appl)
498
+ extendSubschemaMode(subschema, appl)
499
+ const nextContext = {...this.it, ...subschema, items: undefined, props: undefined}
500
+ subschemaCode(nextContext, valid)
501
+ return nextContext
502
+ }
503
+
504
+ mergeEvaluated(schemaCxt: SchemaCxt, toName?: typeof Name): void {
505
+ const {it, gen} = this
506
+ if (!it.opts.unevaluated) return
507
+ if (it.props !== true && schemaCxt.props !== undefined) {
508
+ it.props = mergeEvaluated.props(gen, schemaCxt.props, it.props, toName)
509
+ }
510
+ if (it.items !== true && schemaCxt.items !== undefined) {
511
+ it.items = mergeEvaluated.items(gen, schemaCxt.items, it.items, toName)
512
+ }
513
+ }
514
+
515
+ mergeValidEvaluated(schemaCxt: SchemaCxt, valid: Name): boolean | void {
516
+ const {it, gen} = this
517
+ if (it.opts.unevaluated && (it.props !== true || it.items !== true)) {
518
+ gen.if(valid, () => this.mergeEvaluated(schemaCxt, Name))
519
+ return true
520
+ }
521
+ }
522
+ }
523
+
524
+ function keywordCode(
525
+ it: SchemaObjCxt,
526
+ keyword: string,
527
+ def: AddedKeywordDefinition,
528
+ ruleType?: JSONType
529
+ ): void {
530
+ const cxt = new KeywordCxt(it, def, keyword)
531
+ if ("code" in def) {
532
+ def.code(cxt, ruleType)
533
+ } else if (cxt.$data && def.validate) {
534
+ funcKeywordCode(cxt, def)
535
+ } else if ("macro" in def) {
536
+ macroKeywordCode(cxt, def)
537
+ } else if (def.compile || def.validate) {
538
+ funcKeywordCode(cxt, def)
539
+ }
540
+ }
541
+
542
+ const JSON_POINTER = /^\/(?:[^~]|~0|~1)*$/
543
+ const RELATIVE_JSON_POINTER = /^([0-9]+)(#|\/(?:[^~]|~0|~1)*)?$/
544
+ export function getData(
545
+ $data: string,
546
+ {dataLevel, dataNames, dataPathArr}: SchemaCxt
547
+ ): Code | number {
548
+ let jsonPointer
549
+ let data: Code
550
+ if ($data === "") return N.rootData
551
+ if ($data[0] === "/") {
552
+ if (!JSON_POINTER.test($data)) throw new Error(`Invalid JSON-pointer: ${$data}`)
553
+ jsonPointer = $data
554
+ data = N.rootData
555
+ } else {
556
+ const matches = RELATIVE_JSON_POINTER.exec($data)
557
+ if (!matches) throw new Error(`Invalid JSON-pointer: ${$data}`)
558
+ const up: number = +matches[1]
559
+ jsonPointer = matches[2]
560
+ if (jsonPointer === "#") {
561
+ if (up >= dataLevel) throw new Error(errorMsg("property/index", up))
562
+ return dataPathArr[dataLevel - up]
563
+ }
564
+ if (up > dataLevel) throw new Error(errorMsg("data", up))
565
+ data = dataNames[dataLevel - up]
566
+ if (!jsonPointer) return data
567
+ }
568
+
569
+ let expr = data
570
+ const segments = jsonPointer.split("/")
571
+ for (const segment of segments) {
572
+ if (segment) {
573
+ data = _`${data}${getProperty(unescapeJsonPointer(segment))}`
574
+ expr = _`${expr} && ${data}`
575
+ }
576
+ }
577
+ return expr
578
+
579
+ function errorMsg(pointerType: string, up: number): string {
580
+ return `Cannot access ${pointerType} ${up} levels up, current level is ${dataLevel}`
581
+ }
582
+ }
platform/aiml/elizabeth/e-1-first_session/claude-code-router/node_modules/ajv/lib/compile/validate/keyword.ts ADDED
@@ -0,0 +1,171 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import type {KeywordCxt} from "."
2
+ import type {
3
+ AnySchema,
4
+ SchemaValidateFunction,
5
+ AnyValidateFunction,
6
+ AddedKeywordDefinition,
7
+ MacroKeywordDefinition,
8
+ FuncKeywordDefinition,
9
+ } from "../../types"
10
+ import type {SchemaObjCxt} from ".."
11
+ import {_, nil, not, stringify, Code, Name, CodeGen} from "../codegen"
12
+ import N from "../names"
13
+ import type {JSONType} from "../rules"
14
+ import {callValidateCode} from "../../vocabularies/code"
15
+ import {extendErrors} from "../errors"
16
+
17
+ type KeywordCompilationResult = AnySchema | SchemaValidateFunction | AnyValidateFunction
18
+
19
+ export function macroKeywordCode(cxt: KeywordCxt, def: MacroKeywordDefinition): void {
20
+ const {gen, keyword, schema, parentSchema, it} = cxt
21
+ const macroSchema = def.macro.call(it.self, schema, parentSchema, it)
22
+ const schemaRef = useKeyword(gen, keyword, macroSchema)
23
+ if (it.opts.validateSchema !== false) it.self.validateSchema(macroSchema, true)
24
+
25
+ const valid = gen.name("valid")
26
+ cxt.subschema(
27
+ {
28
+ schema: macroSchema,
29
+ schemaPath: nil,
30
+ errSchemaPath: `${it.errSchemaPath}/${keyword}`,
31
+ topSchemaRef: schemaRef,
32
+ compositeRule: true,
33
+ },
34
+ valid
35
+ )
36
+ cxt.pass(valid, () => cxt.error(true))
37
+ }
38
+
39
+ export function funcKeywordCode(cxt: KeywordCxt, def: FuncKeywordDefinition): void {
40
+ const {gen, keyword, schema, parentSchema, $data, it} = cxt
41
+ checkAsyncKeyword(it, def)
42
+ const validate =
43
+ !$data && def.compile ? def.compile.call(it.self, schema, parentSchema, it) : def.validate
44
+ const validateRef = useKeyword(gen, keyword, validate)
45
+ const valid = gen.let("valid")
46
+ cxt.block$data(valid, validateKeyword)
47
+ cxt.ok(def.valid ?? valid)
48
+
49
+ function validateKeyword(): void {
50
+ if (def.errors === false) {
51
+ assignValid()
52
+ if (def.modifying) modifyData(cxt)
53
+ reportErrs(() => cxt.error())
54
+ } else {
55
+ const ruleErrs = def.async ? validateAsync() : validateSync()
56
+ if (def.modifying) modifyData(cxt)
57
+ reportErrs(() => addErrs(cxt, ruleErrs))
58
+ }
59
+ }
60
+
61
+ function validateAsync(): Name {
62
+ const ruleErrs = gen.let("ruleErrs", null)
63
+ gen.try(
64
+ () => assignValid(_`await `),
65
+ (e) =>
66
+ gen.assign(valid, false).if(
67
+ _`${e} instanceof ${it.ValidationError as Name}`,
68
+ () => gen.assign(ruleErrs, _`${e}.errors`),
69
+ () => gen.throw(e)
70
+ )
71
+ )
72
+ return ruleErrs
73
+ }
74
+
75
+ function validateSync(): Code {
76
+ const validateErrs = _`${validateRef}.errors`
77
+ gen.assign(validateErrs, null)
78
+ assignValid(nil)
79
+ return validateErrs
80
+ }
81
+
82
+ function assignValid(_await: Code = def.async ? _`await ` : nil): void {
83
+ const passCxt = it.opts.passContext ? N.this : N.self
84
+ const passSchema = !(("compile" in def && !$data) || def.schema === false)
85
+ gen.assign(
86
+ valid,
87
+ _`${_await}${callValidateCode(cxt, validateRef, passCxt, passSchema)}`,
88
+ def.modifying
89
+ )
90
+ }
91
+
92
+ function reportErrs(errors: () => void): void {
93
+ gen.if(not(def.valid ?? valid), errors)
94
+ }
95
+ }
96
+
97
+ function modifyData(cxt: KeywordCxt): void {
98
+ const {gen, data, it} = cxt
99
+ gen.if(it.parentData, () => gen.assign(data, _`${it.parentData}[${it.parentDataProperty}]`))
100
+ }
101
+
102
+ function addErrs(cxt: KeywordCxt, errs: Code): void {
103
+ const {gen} = cxt
104
+ gen.if(
105
+ _`Array.isArray(${errs})`,
106
+ () => {
107
+ gen
108
+ .assign(N.vErrors, _`${N.vErrors} === null ? ${errs} : ${N.vErrors}.concat(${errs})`)
109
+ .assign(N.errors, _`${N.vErrors}.length`)
110
+ extendErrors(cxt)
111
+ },
112
+ () => cxt.error()
113
+ )
114
+ }
115
+
116
+ function checkAsyncKeyword({schemaEnv}: SchemaObjCxt, def: FuncKeywordDefinition): void {
117
+ if (def.async && !schemaEnv.$async) throw new Error("async keyword in sync schema")
118
+ }
119
+
120
+ function useKeyword(gen: CodeGen, keyword: string, result?: KeywordCompilationResult): Name {
121
+ if (result === undefined) throw new Error(`keyword "${keyword}" failed to compile`)
122
+ return gen.scopeValue(
123
+ "keyword",
124
+ typeof result == "function" ? {ref: result} : {ref: result, code: stringify(result)}
125
+ )
126
+ }
127
+
128
+ export function validSchemaType(
129
+ schema: unknown,
130
+ schemaType: JSONType[],
131
+ allowUndefined = false
132
+ ): boolean {
133
+ // TODO add tests
134
+ return (
135
+ !schemaType.length ||
136
+ schemaType.some((st) =>
137
+ st === "array"
138
+ ? Array.isArray(schema)
139
+ : st === "object"
140
+ ? schema && typeof schema == "object" && !Array.isArray(schema)
141
+ : typeof schema == st || (allowUndefined && typeof schema == "undefined")
142
+ )
143
+ )
144
+ }
145
+
146
+ export function validateKeywordUsage(
147
+ {schema, opts, self, errSchemaPath}: SchemaObjCxt,
148
+ def: AddedKeywordDefinition,
149
+ keyword: string
150
+ ): void {
151
+ /* istanbul ignore if */
152
+ if (Array.isArray(def.keyword) ? !def.keyword.includes(keyword) : def.keyword !== keyword) {
153
+ throw new Error("ajv implementation error")
154
+ }
155
+
156
+ const deps = def.dependencies
157
+ if (deps?.some((kwd) => !Object.prototype.hasOwnProperty.call(schema, kwd))) {
158
+ throw new Error(`parent schema must have dependencies of ${keyword}: ${deps.join(",")}`)
159
+ }
160
+
161
+ if (def.validateSchema) {
162
+ const valid = def.validateSchema(schema[keyword])
163
+ if (!valid) {
164
+ const msg =
165
+ `keyword "${keyword}" value is invalid at path "${errSchemaPath}": ` +
166
+ self.errorsText(def.validateSchema.errors)
167
+ if (opts.validateSchema === "log") self.logger.error(msg)
168
+ else throw new Error(msg)
169
+ }
170
+ }
171
+ }
platform/aiml/elizabeth/e-1-first_session/claude-code-router/node_modules/ajv/lib/compile/validate/subschema.ts ADDED
@@ -0,0 +1,135 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import type {AnySchema} from "../../types"
2
+ import type {SchemaObjCxt} from ".."
3
+ import {_, str, getProperty, Code, Name} from "../codegen"
4
+ import {escapeFragment, getErrorPath, Type} from "../util"
5
+ import type {JSONType} from "../rules"
6
+
7
+ export interface SubschemaContext {
8
+ // TODO use Optional? align with SchemCxt property types
9
+ schema: AnySchema
10
+ schemaPath: Code
11
+ errSchemaPath: string
12
+ topSchemaRef?: Code
13
+ errorPath?: Code
14
+ dataLevel?: number
15
+ dataTypes?: JSONType[]
16
+ data?: Name
17
+ parentData?: Name
18
+ parentDataProperty?: Code | number
19
+ dataNames?: Name[]
20
+ dataPathArr?: (Code | number)[]
21
+ propertyName?: Name
22
+ jtdDiscriminator?: string
23
+ jtdMetadata?: boolean
24
+ compositeRule?: true
25
+ createErrors?: boolean
26
+ allErrors?: boolean
27
+ }
28
+
29
+ export type SubschemaArgs = Partial<{
30
+ keyword: string
31
+ schemaProp: string | number
32
+ schema: AnySchema
33
+ schemaPath: Code
34
+ errSchemaPath: string
35
+ topSchemaRef: Code
36
+ data: Name | Code
37
+ dataProp: Code | string | number
38
+ dataTypes: JSONType[]
39
+ definedProperties: Set<string>
40
+ propertyName: Name
41
+ dataPropType: Type
42
+ jtdDiscriminator: string
43
+ jtdMetadata: boolean
44
+ compositeRule: true
45
+ createErrors: boolean
46
+ allErrors: boolean
47
+ }>
48
+
49
+ export function getSubschema(
50
+ it: SchemaObjCxt,
51
+ {keyword, schemaProp, schema, schemaPath, errSchemaPath, topSchemaRef}: SubschemaArgs
52
+ ): SubschemaContext {
53
+ if (keyword !== undefined && schema !== undefined) {
54
+ throw new Error('both "keyword" and "schema" passed, only one allowed')
55
+ }
56
+
57
+ if (keyword !== undefined) {
58
+ const sch = it.schema[keyword]
59
+ return schemaProp === undefined
60
+ ? {
61
+ schema: sch,
62
+ schemaPath: _`${it.schemaPath}${getProperty(keyword)}`,
63
+ errSchemaPath: `${it.errSchemaPath}/${keyword}`,
64
+ }
65
+ : {
66
+ schema: sch[schemaProp],
67
+ schemaPath: _`${it.schemaPath}${getProperty(keyword)}${getProperty(schemaProp)}`,
68
+ errSchemaPath: `${it.errSchemaPath}/${keyword}/${escapeFragment(schemaProp)}`,
69
+ }
70
+ }
71
+
72
+ if (schema !== undefined) {
73
+ if (schemaPath === undefined || errSchemaPath === undefined || topSchemaRef === undefined) {
74
+ throw new Error('"schemaPath", "errSchemaPath" and "topSchemaRef" are required with "schema"')
75
+ }
76
+ return {
77
+ schema,
78
+ schemaPath,
79
+ topSchemaRef,
80
+ errSchemaPath,
81
+ }
82
+ }
83
+
84
+ throw new Error('either "keyword" or "schema" must be passed')
85
+ }
86
+
87
+ export function extendSubschemaData(
88
+ subschema: SubschemaContext,
89
+ it: SchemaObjCxt,
90
+ {dataProp, dataPropType: dpType, data, dataTypes, propertyName}: SubschemaArgs
91
+ ): void {
92
+ if (data !== undefined && dataProp !== undefined) {
93
+ throw new Error('both "data" and "dataProp" passed, only one allowed')
94
+ }
95
+
96
+ const {gen} = it
97
+
98
+ if (dataProp !== undefined) {
99
+ const {errorPath, dataPathArr, opts} = it
100
+ const nextData = gen.let("data", _`${it.data}${getProperty(dataProp)}`, true)
101
+ dataContextProps(nextData)
102
+ subschema.errorPath = str`${errorPath}${getErrorPath(dataProp, dpType, opts.jsPropertySyntax)}`
103
+ subschema.parentDataProperty = _`${dataProp}`
104
+ subschema.dataPathArr = [...dataPathArr, subschema.parentDataProperty]
105
+ }
106
+
107
+ if (data !== undefined) {
108
+ const nextData = data instanceof Name ? data : gen.let("data", data, true) // replaceable if used once?
109
+ dataContextProps(nextData)
110
+ if (propertyName !== undefined) subschema.propertyName = propertyName
111
+ // TODO something is possibly wrong here with not changing parentDataProperty and not appending dataPathArr
112
+ }
113
+
114
+ if (dataTypes) subschema.dataTypes = dataTypes
115
+
116
+ function dataContextProps(_nextData: Name): void {
117
+ subschema.data = _nextData
118
+ subschema.dataLevel = it.dataLevel + 1
119
+ subschema.dataTypes = []
120
+ it.definedProperties = new Set<string>()
121
+ subschema.parentData = it.data
122
+ subschema.dataNames = [...it.dataNames, _nextData]
123
+ }
124
+ }
125
+
126
+ export function extendSubschemaMode(
127
+ subschema: SubschemaContext,
128
+ {jtdDiscriminator, jtdMetadata, compositeRule, createErrors, allErrors}: SubschemaArgs
129
+ ): void {
130
+ if (compositeRule !== undefined) subschema.compositeRule = compositeRule
131
+ if (createErrors !== undefined) subschema.createErrors = createErrors
132
+ if (allErrors !== undefined) subschema.allErrors = allErrors
133
+ subschema.jtdDiscriminator = jtdDiscriminator // not inherited
134
+ subschema.jtdMetadata = jtdMetadata // not inherited
135
+ }
platform/aiml/elizabeth/e-1-first_session/claude-code-router/node_modules/ajv/lib/refs/data.json ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "$id": "https://raw.githubusercontent.com/ajv-validator/ajv/master/lib/refs/data.json#",
3
+ "description": "Meta-schema for $data reference (JSON AnySchema extension proposal)",
4
+ "type": "object",
5
+ "required": ["$data"],
6
+ "properties": {
7
+ "$data": {
8
+ "type": "string",
9
+ "anyOf": [{"format": "relative-json-pointer"}, {"format": "json-pointer"}]
10
+ }
11
+ },
12
+ "additionalProperties": false
13
+ }
platform/aiml/elizabeth/e-1-first_session/claude-code-router/node_modules/ajv/lib/refs/json-schema-2019-09/index.ts ADDED
@@ -0,0 +1,28 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import type Ajv from "../../core"
2
+ import type {AnySchemaObject} from "../../types"
3
+ import * as metaSchema from "./schema.json"
4
+ import * as applicator from "./meta/applicator.json"
5
+ import * as content from "./meta/content.json"
6
+ import * as core from "./meta/core.json"
7
+ import * as format from "./meta/format.json"
8
+ import * as metadata from "./meta/meta-data.json"
9
+ import * as validation from "./meta/validation.json"
10
+
11
+ const META_SUPPORT_DATA = ["/properties"]
12
+
13
+ export default function addMetaSchema2019(this: Ajv, $data?: boolean): Ajv {
14
+ ;[
15
+ metaSchema,
16
+ applicator,
17
+ content,
18
+ core,
19
+ with$data(this, format),
20
+ metadata,
21
+ with$data(this, validation),
22
+ ].forEach((sch) => this.addMetaSchema(sch, undefined, false))
23
+ return this
24
+
25
+ function with$data(ajv: Ajv, sch: AnySchemaObject): AnySchemaObject {
26
+ return $data ? ajv.$dataMetaSchema(sch, META_SUPPORT_DATA) : sch
27
+ }
28
+ }
platform/aiml/elizabeth/e-1-first_session/claude-code-router/node_modules/ajv/lib/refs/json-schema-2019-09/meta/applicator.json ADDED
@@ -0,0 +1,53 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "$schema": "https://json-schema.org/draft/2019-09/schema",
3
+ "$id": "https://json-schema.org/draft/2019-09/meta/applicator",
4
+ "$vocabulary": {
5
+ "https://json-schema.org/draft/2019-09/vocab/applicator": true
6
+ },
7
+ "$recursiveAnchor": true,
8
+
9
+ "title": "Applicator vocabulary meta-schema",
10
+ "type": ["object", "boolean"],
11
+ "properties": {
12
+ "additionalItems": {"$recursiveRef": "#"},
13
+ "unevaluatedItems": {"$recursiveRef": "#"},
14
+ "items": {
15
+ "anyOf": [{"$recursiveRef": "#"}, {"$ref": "#/$defs/schemaArray"}]
16
+ },
17
+ "contains": {"$recursiveRef": "#"},
18
+ "additionalProperties": {"$recursiveRef": "#"},
19
+ "unevaluatedProperties": {"$recursiveRef": "#"},
20
+ "properties": {
21
+ "type": "object",
22
+ "additionalProperties": {"$recursiveRef": "#"},
23
+ "default": {}
24
+ },
25
+ "patternProperties": {
26
+ "type": "object",
27
+ "additionalProperties": {"$recursiveRef": "#"},
28
+ "propertyNames": {"format": "regex"},
29
+ "default": {}
30
+ },
31
+ "dependentSchemas": {
32
+ "type": "object",
33
+ "additionalProperties": {
34
+ "$recursiveRef": "#"
35
+ }
36
+ },
37
+ "propertyNames": {"$recursiveRef": "#"},
38
+ "if": {"$recursiveRef": "#"},
39
+ "then": {"$recursiveRef": "#"},
40
+ "else": {"$recursiveRef": "#"},
41
+ "allOf": {"$ref": "#/$defs/schemaArray"},
42
+ "anyOf": {"$ref": "#/$defs/schemaArray"},
43
+ "oneOf": {"$ref": "#/$defs/schemaArray"},
44
+ "not": {"$recursiveRef": "#"}
45
+ },
46
+ "$defs": {
47
+ "schemaArray": {
48
+ "type": "array",
49
+ "minItems": 1,
50
+ "items": {"$recursiveRef": "#"}
51
+ }
52
+ }
53
+ }
platform/aiml/elizabeth/e-1-first_session/claude-code-router/node_modules/ajv/lib/refs/json-schema-2019-09/meta/content.json ADDED
@@ -0,0 +1,17 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "$schema": "https://json-schema.org/draft/2019-09/schema",
3
+ "$id": "https://json-schema.org/draft/2019-09/meta/content",
4
+ "$vocabulary": {
5
+ "https://json-schema.org/draft/2019-09/vocab/content": true
6
+ },
7
+ "$recursiveAnchor": true,
8
+
9
+ "title": "Content vocabulary meta-schema",
10
+
11
+ "type": ["object", "boolean"],
12
+ "properties": {
13
+ "contentMediaType": {"type": "string"},
14
+ "contentEncoding": {"type": "string"},
15
+ "contentSchema": {"$recursiveRef": "#"}
16
+ }
17
+ }
platform/aiml/elizabeth/e-1-first_session/claude-code-router/node_modules/ajv/lib/refs/json-schema-2019-09/meta/core.json ADDED
@@ -0,0 +1,57 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "$schema": "https://json-schema.org/draft/2019-09/schema",
3
+ "$id": "https://json-schema.org/draft/2019-09/meta/core",
4
+ "$vocabulary": {
5
+ "https://json-schema.org/draft/2019-09/vocab/core": true
6
+ },
7
+ "$recursiveAnchor": true,
8
+
9
+ "title": "Core vocabulary meta-schema",
10
+ "type": ["object", "boolean"],
11
+ "properties": {
12
+ "$id": {
13
+ "type": "string",
14
+ "format": "uri-reference",
15
+ "$comment": "Non-empty fragments not allowed.",
16
+ "pattern": "^[^#]*#?$"
17
+ },
18
+ "$schema": {
19
+ "type": "string",
20
+ "format": "uri"
21
+ },
22
+ "$anchor": {
23
+ "type": "string",
24
+ "pattern": "^[A-Za-z][-A-Za-z0-9.:_]*$"
25
+ },
26
+ "$ref": {
27
+ "type": "string",
28
+ "format": "uri-reference"
29
+ },
30
+ "$recursiveRef": {
31
+ "type": "string",
32
+ "format": "uri-reference"
33
+ },
34
+ "$recursiveAnchor": {
35
+ "type": "boolean",
36
+ "default": false
37
+ },
38
+ "$vocabulary": {
39
+ "type": "object",
40
+ "propertyNames": {
41
+ "type": "string",
42
+ "format": "uri"
43
+ },
44
+ "additionalProperties": {
45
+ "type": "boolean"
46
+ }
47
+ },
48
+ "$comment": {
49
+ "type": "string"
50
+ },
51
+ "$defs": {
52
+ "type": "object",
53
+ "additionalProperties": {"$recursiveRef": "#"},
54
+ "default": {}
55
+ }
56
+ }
57
+ }
platform/aiml/elizabeth/e-1-first_session/claude-code-router/node_modules/ajv/lib/refs/json-schema-2019-09/meta/format.json ADDED
@@ -0,0 +1,14 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "$schema": "https://json-schema.org/draft/2019-09/schema",
3
+ "$id": "https://json-schema.org/draft/2019-09/meta/format",
4
+ "$vocabulary": {
5
+ "https://json-schema.org/draft/2019-09/vocab/format": true
6
+ },
7
+ "$recursiveAnchor": true,
8
+
9
+ "title": "Format vocabulary meta-schema",
10
+ "type": ["object", "boolean"],
11
+ "properties": {
12
+ "format": {"type": "string"}
13
+ }
14
+ }
platform/aiml/elizabeth/e-1-first_session/claude-code-router/node_modules/ajv/lib/refs/json-schema-2019-09/meta/meta-data.json ADDED
@@ -0,0 +1,37 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "$schema": "https://json-schema.org/draft/2019-09/schema",
3
+ "$id": "https://json-schema.org/draft/2019-09/meta/meta-data",
4
+ "$vocabulary": {
5
+ "https://json-schema.org/draft/2019-09/vocab/meta-data": true
6
+ },
7
+ "$recursiveAnchor": true,
8
+
9
+ "title": "Meta-data vocabulary meta-schema",
10
+
11
+ "type": ["object", "boolean"],
12
+ "properties": {
13
+ "title": {
14
+ "type": "string"
15
+ },
16
+ "description": {
17
+ "type": "string"
18
+ },
19
+ "default": true,
20
+ "deprecated": {
21
+ "type": "boolean",
22
+ "default": false
23
+ },
24
+ "readOnly": {
25
+ "type": "boolean",
26
+ "default": false
27
+ },
28
+ "writeOnly": {
29
+ "type": "boolean",
30
+ "default": false
31
+ },
32
+ "examples": {
33
+ "type": "array",
34
+ "items": true
35
+ }
36
+ }
37
+ }
platform/aiml/elizabeth/e-1-first_session/claude-code-router/node_modules/ajv/lib/refs/json-schema-2019-09/meta/validation.json ADDED
@@ -0,0 +1,90 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "$schema": "https://json-schema.org/draft/2019-09/schema",
3
+ "$id": "https://json-schema.org/draft/2019-09/meta/validation",
4
+ "$vocabulary": {
5
+ "https://json-schema.org/draft/2019-09/vocab/validation": true
6
+ },
7
+ "$recursiveAnchor": true,
8
+
9
+ "title": "Validation vocabulary meta-schema",
10
+ "type": ["object", "boolean"],
11
+ "properties": {
12
+ "multipleOf": {
13
+ "type": "number",
14
+ "exclusiveMinimum": 0
15
+ },
16
+ "maximum": {
17
+ "type": "number"
18
+ },
19
+ "exclusiveMaximum": {
20
+ "type": "number"
21
+ },
22
+ "minimum": {
23
+ "type": "number"
24
+ },
25
+ "exclusiveMinimum": {
26
+ "type": "number"
27
+ },
28
+ "maxLength": {"$ref": "#/$defs/nonNegativeInteger"},
29
+ "minLength": {"$ref": "#/$defs/nonNegativeIntegerDefault0"},
30
+ "pattern": {
31
+ "type": "string",
32
+ "format": "regex"
33
+ },
34
+ "maxItems": {"$ref": "#/$defs/nonNegativeInteger"},
35
+ "minItems": {"$ref": "#/$defs/nonNegativeIntegerDefault0"},
36
+ "uniqueItems": {
37
+ "type": "boolean",
38
+ "default": false
39
+ },
40
+ "maxContains": {"$ref": "#/$defs/nonNegativeInteger"},
41
+ "minContains": {
42
+ "$ref": "#/$defs/nonNegativeInteger",
43
+ "default": 1
44
+ },
45
+ "maxProperties": {"$ref": "#/$defs/nonNegativeInteger"},
46
+ "minProperties": {"$ref": "#/$defs/nonNegativeIntegerDefault0"},
47
+ "required": {"$ref": "#/$defs/stringArray"},
48
+ "dependentRequired": {
49
+ "type": "object",
50
+ "additionalProperties": {
51
+ "$ref": "#/$defs/stringArray"
52
+ }
53
+ },
54
+ "const": true,
55
+ "enum": {
56
+ "type": "array",
57
+ "items": true
58
+ },
59
+ "type": {
60
+ "anyOf": [
61
+ {"$ref": "#/$defs/simpleTypes"},
62
+ {
63
+ "type": "array",
64
+ "items": {"$ref": "#/$defs/simpleTypes"},
65
+ "minItems": 1,
66
+ "uniqueItems": true
67
+ }
68
+ ]
69
+ }
70
+ },
71
+ "$defs": {
72
+ "nonNegativeInteger": {
73
+ "type": "integer",
74
+ "minimum": 0
75
+ },
76
+ "nonNegativeIntegerDefault0": {
77
+ "$ref": "#/$defs/nonNegativeInteger",
78
+ "default": 0
79
+ },
80
+ "simpleTypes": {
81
+ "enum": ["array", "boolean", "integer", "null", "number", "object", "string"]
82
+ },
83
+ "stringArray": {
84
+ "type": "array",
85
+ "items": {"type": "string"},
86
+ "uniqueItems": true,
87
+ "default": []
88
+ }
89
+ }
90
+ }
platform/aiml/elizabeth/e-1-first_session/claude-code-router/node_modules/ajv/lib/refs/json-schema-2019-09/schema.json ADDED
@@ -0,0 +1,39 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "$schema": "https://json-schema.org/draft/2019-09/schema",
3
+ "$id": "https://json-schema.org/draft/2019-09/schema",
4
+ "$vocabulary": {
5
+ "https://json-schema.org/draft/2019-09/vocab/core": true,
6
+ "https://json-schema.org/draft/2019-09/vocab/applicator": true,
7
+ "https://json-schema.org/draft/2019-09/vocab/validation": true,
8
+ "https://json-schema.org/draft/2019-09/vocab/meta-data": true,
9
+ "https://json-schema.org/draft/2019-09/vocab/format": false,
10
+ "https://json-schema.org/draft/2019-09/vocab/content": true
11
+ },
12
+ "$recursiveAnchor": true,
13
+
14
+ "title": "Core and Validation specifications meta-schema",
15
+ "allOf": [
16
+ {"$ref": "meta/core"},
17
+ {"$ref": "meta/applicator"},
18
+ {"$ref": "meta/validation"},
19
+ {"$ref": "meta/meta-data"},
20
+ {"$ref": "meta/format"},
21
+ {"$ref": "meta/content"}
22
+ ],
23
+ "type": ["object", "boolean"],
24
+ "properties": {
25
+ "definitions": {
26
+ "$comment": "While no longer an official keyword as it is replaced by $defs, this keyword is retained in the meta-schema to prevent incompatible extensions as it remains in common use.",
27
+ "type": "object",
28
+ "additionalProperties": {"$recursiveRef": "#"},
29
+ "default": {}
30
+ },
31
+ "dependencies": {
32
+ "$comment": "\"dependencies\" is no longer a keyword, but schema authors should avoid redefining it to facilitate a smooth transition to \"dependentSchemas\" and \"dependentRequired\"",
33
+ "type": "object",
34
+ "additionalProperties": {
35
+ "anyOf": [{"$recursiveRef": "#"}, {"$ref": "meta/validation#/$defs/stringArray"}]
36
+ }
37
+ }
38
+ }
39
+ }
platform/aiml/elizabeth/e-1-first_session/claude-code-router/node_modules/ajv/lib/refs/json-schema-2020-12/index.ts ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import type Ajv from "../../core"
2
+ import type {AnySchemaObject} from "../../types"
3
+ import * as metaSchema from "./schema.json"
4
+ import * as applicator from "./meta/applicator.json"
5
+ import * as unevaluated from "./meta/unevaluated.json"
6
+ import * as content from "./meta/content.json"
7
+ import * as core from "./meta/core.json"
8
+ import * as format from "./meta/format-annotation.json"
9
+ import * as metadata from "./meta/meta-data.json"
10
+ import * as validation from "./meta/validation.json"
11
+
12
+ const META_SUPPORT_DATA = ["/properties"]
13
+
14
+ export default function addMetaSchema2020(this: Ajv, $data?: boolean): Ajv {
15
+ ;[
16
+ metaSchema,
17
+ applicator,
18
+ unevaluated,
19
+ content,
20
+ core,
21
+ with$data(this, format),
22
+ metadata,
23
+ with$data(this, validation),
24
+ ].forEach((sch) => this.addMetaSchema(sch, undefined, false))
25
+ return this
26
+
27
+ function with$data(ajv: Ajv, sch: AnySchemaObject): AnySchemaObject {
28
+ return $data ? ajv.$dataMetaSchema(sch, META_SUPPORT_DATA) : sch
29
+ }
30
+ }
platform/aiml/elizabeth/e-1-first_session/claude-code-router/node_modules/ajv/lib/refs/json-schema-2020-12/meta/applicator.json ADDED
@@ -0,0 +1,48 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
3
+ "$id": "https://json-schema.org/draft/2020-12/meta/applicator",
4
+ "$vocabulary": {
5
+ "https://json-schema.org/draft/2020-12/vocab/applicator": true
6
+ },
7
+ "$dynamicAnchor": "meta",
8
+
9
+ "title": "Applicator vocabulary meta-schema",
10
+ "type": ["object", "boolean"],
11
+ "properties": {
12
+ "prefixItems": {"$ref": "#/$defs/schemaArray"},
13
+ "items": {"$dynamicRef": "#meta"},
14
+ "contains": {"$dynamicRef": "#meta"},
15
+ "additionalProperties": {"$dynamicRef": "#meta"},
16
+ "properties": {
17
+ "type": "object",
18
+ "additionalProperties": {"$dynamicRef": "#meta"},
19
+ "default": {}
20
+ },
21
+ "patternProperties": {
22
+ "type": "object",
23
+ "additionalProperties": {"$dynamicRef": "#meta"},
24
+ "propertyNames": {"format": "regex"},
25
+ "default": {}
26
+ },
27
+ "dependentSchemas": {
28
+ "type": "object",
29
+ "additionalProperties": {"$dynamicRef": "#meta"},
30
+ "default": {}
31
+ },
32
+ "propertyNames": {"$dynamicRef": "#meta"},
33
+ "if": {"$dynamicRef": "#meta"},
34
+ "then": {"$dynamicRef": "#meta"},
35
+ "else": {"$dynamicRef": "#meta"},
36
+ "allOf": {"$ref": "#/$defs/schemaArray"},
37
+ "anyOf": {"$ref": "#/$defs/schemaArray"},
38
+ "oneOf": {"$ref": "#/$defs/schemaArray"},
39
+ "not": {"$dynamicRef": "#meta"}
40
+ },
41
+ "$defs": {
42
+ "schemaArray": {
43
+ "type": "array",
44
+ "minItems": 1,
45
+ "items": {"$dynamicRef": "#meta"}
46
+ }
47
+ }
48
+ }
platform/aiml/elizabeth/e-1-first_session/claude-code-router/node_modules/ajv/lib/refs/json-schema-2020-12/meta/content.json ADDED
@@ -0,0 +1,17 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
3
+ "$id": "https://json-schema.org/draft/2020-12/meta/content",
4
+ "$vocabulary": {
5
+ "https://json-schema.org/draft/2020-12/vocab/content": true
6
+ },
7
+ "$dynamicAnchor": "meta",
8
+
9
+ "title": "Content vocabulary meta-schema",
10
+
11
+ "type": ["object", "boolean"],
12
+ "properties": {
13
+ "contentEncoding": {"type": "string"},
14
+ "contentMediaType": {"type": "string"},
15
+ "contentSchema": {"$dynamicRef": "#meta"}
16
+ }
17
+ }
platform/aiml/elizabeth/e-1-first_session/claude-code-router/node_modules/ajv/lib/refs/json-schema-2020-12/meta/core.json ADDED
@@ -0,0 +1,51 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
3
+ "$id": "https://json-schema.org/draft/2020-12/meta/core",
4
+ "$vocabulary": {
5
+ "https://json-schema.org/draft/2020-12/vocab/core": true
6
+ },
7
+ "$dynamicAnchor": "meta",
8
+
9
+ "title": "Core vocabulary meta-schema",
10
+ "type": ["object", "boolean"],
11
+ "properties": {
12
+ "$id": {
13
+ "$ref": "#/$defs/uriReferenceString",
14
+ "$comment": "Non-empty fragments not allowed.",
15
+ "pattern": "^[^#]*#?$"
16
+ },
17
+ "$schema": {"$ref": "#/$defs/uriString"},
18
+ "$ref": {"$ref": "#/$defs/uriReferenceString"},
19
+ "$anchor": {"$ref": "#/$defs/anchorString"},
20
+ "$dynamicRef": {"$ref": "#/$defs/uriReferenceString"},
21
+ "$dynamicAnchor": {"$ref": "#/$defs/anchorString"},
22
+ "$vocabulary": {
23
+ "type": "object",
24
+ "propertyNames": {"$ref": "#/$defs/uriString"},
25
+ "additionalProperties": {
26
+ "type": "boolean"
27
+ }
28
+ },
29
+ "$comment": {
30
+ "type": "string"
31
+ },
32
+ "$defs": {
33
+ "type": "object",
34
+ "additionalProperties": {"$dynamicRef": "#meta"}
35
+ }
36
+ },
37
+ "$defs": {
38
+ "anchorString": {
39
+ "type": "string",
40
+ "pattern": "^[A-Za-z_][-A-Za-z0-9._]*$"
41
+ },
42
+ "uriString": {
43
+ "type": "string",
44
+ "format": "uri"
45
+ },
46
+ "uriReferenceString": {
47
+ "type": "string",
48
+ "format": "uri-reference"
49
+ }
50
+ }
51
+ }
platform/aiml/elizabeth/e-1-first_session/claude-code-router/node_modules/ajv/lib/refs/json-schema-2020-12/meta/format-annotation.json ADDED
@@ -0,0 +1,14 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
3
+ "$id": "https://json-schema.org/draft/2020-12/meta/format-annotation",
4
+ "$vocabulary": {
5
+ "https://json-schema.org/draft/2020-12/vocab/format-annotation": true
6
+ },
7
+ "$dynamicAnchor": "meta",
8
+
9
+ "title": "Format vocabulary meta-schema for annotation results",
10
+ "type": ["object", "boolean"],
11
+ "properties": {
12
+ "format": {"type": "string"}
13
+ }
14
+ }
platform/aiml/elizabeth/e-1-first_session/claude-code-router/node_modules/ajv/lib/refs/json-schema-2020-12/meta/meta-data.json ADDED
@@ -0,0 +1,37 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
3
+ "$id": "https://json-schema.org/draft/2020-12/meta/meta-data",
4
+ "$vocabulary": {
5
+ "https://json-schema.org/draft/2020-12/vocab/meta-data": true
6
+ },
7
+ "$dynamicAnchor": "meta",
8
+
9
+ "title": "Meta-data vocabulary meta-schema",
10
+
11
+ "type": ["object", "boolean"],
12
+ "properties": {
13
+ "title": {
14
+ "type": "string"
15
+ },
16
+ "description": {
17
+ "type": "string"
18
+ },
19
+ "default": true,
20
+ "deprecated": {
21
+ "type": "boolean",
22
+ "default": false
23
+ },
24
+ "readOnly": {
25
+ "type": "boolean",
26
+ "default": false
27
+ },
28
+ "writeOnly": {
29
+ "type": "boolean",
30
+ "default": false
31
+ },
32
+ "examples": {
33
+ "type": "array",
34
+ "items": true
35
+ }
36
+ }
37
+ }
platform/aiml/elizabeth/e-1-first_session/claude-code-router/node_modules/ajv/lib/refs/json-schema-2020-12/meta/unevaluated.json ADDED
@@ -0,0 +1,15 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
3
+ "$id": "https://json-schema.org/draft/2020-12/meta/unevaluated",
4
+ "$vocabulary": {
5
+ "https://json-schema.org/draft/2020-12/vocab/unevaluated": true
6
+ },
7
+ "$dynamicAnchor": "meta",
8
+
9
+ "title": "Unevaluated applicator vocabulary meta-schema",
10
+ "type": ["object", "boolean"],
11
+ "properties": {
12
+ "unevaluatedItems": {"$dynamicRef": "#meta"},
13
+ "unevaluatedProperties": {"$dynamicRef": "#meta"}
14
+ }
15
+ }
platform/aiml/elizabeth/e-1-first_session/claude-code-router/node_modules/ajv/lib/refs/json-schema-2020-12/meta/validation.json ADDED
@@ -0,0 +1,90 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
3
+ "$id": "https://json-schema.org/draft/2020-12/meta/validation",
4
+ "$vocabulary": {
5
+ "https://json-schema.org/draft/2020-12/vocab/validation": true
6
+ },
7
+ "$dynamicAnchor": "meta",
8
+
9
+ "title": "Validation vocabulary meta-schema",
10
+ "type": ["object", "boolean"],
11
+ "properties": {
12
+ "type": {
13
+ "anyOf": [
14
+ {"$ref": "#/$defs/simpleTypes"},
15
+ {
16
+ "type": "array",
17
+ "items": {"$ref": "#/$defs/simpleTypes"},
18
+ "minItems": 1,
19
+ "uniqueItems": true
20
+ }
21
+ ]
22
+ },
23
+ "const": true,
24
+ "enum": {
25
+ "type": "array",
26
+ "items": true
27
+ },
28
+ "multipleOf": {
29
+ "type": "number",
30
+ "exclusiveMinimum": 0
31
+ },
32
+ "maximum": {
33
+ "type": "number"
34
+ },
35
+ "exclusiveMaximum": {
36
+ "type": "number"
37
+ },
38
+ "minimum": {
39
+ "type": "number"
40
+ },
41
+ "exclusiveMinimum": {
42
+ "type": "number"
43
+ },
44
+ "maxLength": {"$ref": "#/$defs/nonNegativeInteger"},
45
+ "minLength": {"$ref": "#/$defs/nonNegativeIntegerDefault0"},
46
+ "pattern": {
47
+ "type": "string",
48
+ "format": "regex"
49
+ },
50
+ "maxItems": {"$ref": "#/$defs/nonNegativeInteger"},
51
+ "minItems": {"$ref": "#/$defs/nonNegativeIntegerDefault0"},
52
+ "uniqueItems": {
53
+ "type": "boolean",
54
+ "default": false
55
+ },
56
+ "maxContains": {"$ref": "#/$defs/nonNegativeInteger"},
57
+ "minContains": {
58
+ "$ref": "#/$defs/nonNegativeInteger",
59
+ "default": 1
60
+ },
61
+ "maxProperties": {"$ref": "#/$defs/nonNegativeInteger"},
62
+ "minProperties": {"$ref": "#/$defs/nonNegativeIntegerDefault0"},
63
+ "required": {"$ref": "#/$defs/stringArray"},
64
+ "dependentRequired": {
65
+ "type": "object",
66
+ "additionalProperties": {
67
+ "$ref": "#/$defs/stringArray"
68
+ }
69
+ }
70
+ },
71
+ "$defs": {
72
+ "nonNegativeInteger": {
73
+ "type": "integer",
74
+ "minimum": 0
75
+ },
76
+ "nonNegativeIntegerDefault0": {
77
+ "$ref": "#/$defs/nonNegativeInteger",
78
+ "default": 0
79
+ },
80
+ "simpleTypes": {
81
+ "enum": ["array", "boolean", "integer", "null", "number", "object", "string"]
82
+ },
83
+ "stringArray": {
84
+ "type": "array",
85
+ "items": {"type": "string"},
86
+ "uniqueItems": true,
87
+ "default": []
88
+ }
89
+ }
90
+ }
platform/aiml/elizabeth/e-1-first_session/claude-code-router/node_modules/ajv/lib/refs/json-schema-2020-12/schema.json ADDED
@@ -0,0 +1,55 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
3
+ "$id": "https://json-schema.org/draft/2020-12/schema",
4
+ "$vocabulary": {
5
+ "https://json-schema.org/draft/2020-12/vocab/core": true,
6
+ "https://json-schema.org/draft/2020-12/vocab/applicator": true,
7
+ "https://json-schema.org/draft/2020-12/vocab/unevaluated": true,
8
+ "https://json-schema.org/draft/2020-12/vocab/validation": true,
9
+ "https://json-schema.org/draft/2020-12/vocab/meta-data": true,
10
+ "https://json-schema.org/draft/2020-12/vocab/format-annotation": true,
11
+ "https://json-schema.org/draft/2020-12/vocab/content": true
12
+ },
13
+ "$dynamicAnchor": "meta",
14
+
15
+ "title": "Core and Validation specifications meta-schema",
16
+ "allOf": [
17
+ {"$ref": "meta/core"},
18
+ {"$ref": "meta/applicator"},
19
+ {"$ref": "meta/unevaluated"},
20
+ {"$ref": "meta/validation"},
21
+ {"$ref": "meta/meta-data"},
22
+ {"$ref": "meta/format-annotation"},
23
+ {"$ref": "meta/content"}
24
+ ],
25
+ "type": ["object", "boolean"],
26
+ "$comment": "This meta-schema also defines keywords that have appeared in previous drafts in order to prevent incompatible extensions as they remain in common use.",
27
+ "properties": {
28
+ "definitions": {
29
+ "$comment": "\"definitions\" has been replaced by \"$defs\".",
30
+ "type": "object",
31
+ "additionalProperties": {"$dynamicRef": "#meta"},
32
+ "deprecated": true,
33
+ "default": {}
34
+ },
35
+ "dependencies": {
36
+ "$comment": "\"dependencies\" has been split and replaced by \"dependentSchemas\" and \"dependentRequired\" in order to serve their differing semantics.",
37
+ "type": "object",
38
+ "additionalProperties": {
39
+ "anyOf": [{"$dynamicRef": "#meta"}, {"$ref": "meta/validation#/$defs/stringArray"}]
40
+ },
41
+ "deprecated": true,
42
+ "default": {}
43
+ },
44
+ "$recursiveAnchor": {
45
+ "$comment": "\"$recursiveAnchor\" has been replaced by \"$dynamicAnchor\".",
46
+ "$ref": "meta/core#/$defs/anchorString",
47
+ "deprecated": true
48
+ },
49
+ "$recursiveRef": {
50
+ "$comment": "\"$recursiveRef\" has been replaced by \"$dynamicRef\".",
51
+ "$ref": "meta/core#/$defs/uriReferenceString",
52
+ "deprecated": true
53
+ }
54
+ }
55
+ }
platform/aiml/elizabeth/e-1-first_session/claude-code-router/node_modules/ajv/lib/refs/json-schema-draft-06.json ADDED
@@ -0,0 +1,137 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "$schema": "http://json-schema.org/draft-06/schema#",
3
+ "$id": "http://json-schema.org/draft-06/schema#",
4
+ "title": "Core schema meta-schema",
5
+ "definitions": {
6
+ "schemaArray": {
7
+ "type": "array",
8
+ "minItems": 1,
9
+ "items": {"$ref": "#"}
10
+ },
11
+ "nonNegativeInteger": {
12
+ "type": "integer",
13
+ "minimum": 0
14
+ },
15
+ "nonNegativeIntegerDefault0": {
16
+ "allOf": [{"$ref": "#/definitions/nonNegativeInteger"}, {"default": 0}]
17
+ },
18
+ "simpleTypes": {
19
+ "enum": ["array", "boolean", "integer", "null", "number", "object", "string"]
20
+ },
21
+ "stringArray": {
22
+ "type": "array",
23
+ "items": {"type": "string"},
24
+ "uniqueItems": true,
25
+ "default": []
26
+ }
27
+ },
28
+ "type": ["object", "boolean"],
29
+ "properties": {
30
+ "$id": {
31
+ "type": "string",
32
+ "format": "uri-reference"
33
+ },
34
+ "$schema": {
35
+ "type": "string",
36
+ "format": "uri"
37
+ },
38
+ "$ref": {
39
+ "type": "string",
40
+ "format": "uri-reference"
41
+ },
42
+ "title": {
43
+ "type": "string"
44
+ },
45
+ "description": {
46
+ "type": "string"
47
+ },
48
+ "default": {},
49
+ "examples": {
50
+ "type": "array",
51
+ "items": {}
52
+ },
53
+ "multipleOf": {
54
+ "type": "number",
55
+ "exclusiveMinimum": 0
56
+ },
57
+ "maximum": {
58
+ "type": "number"
59
+ },
60
+ "exclusiveMaximum": {
61
+ "type": "number"
62
+ },
63
+ "minimum": {
64
+ "type": "number"
65
+ },
66
+ "exclusiveMinimum": {
67
+ "type": "number"
68
+ },
69
+ "maxLength": {"$ref": "#/definitions/nonNegativeInteger"},
70
+ "minLength": {"$ref": "#/definitions/nonNegativeIntegerDefault0"},
71
+ "pattern": {
72
+ "type": "string",
73
+ "format": "regex"
74
+ },
75
+ "additionalItems": {"$ref": "#"},
76
+ "items": {
77
+ "anyOf": [{"$ref": "#"}, {"$ref": "#/definitions/schemaArray"}],
78
+ "default": {}
79
+ },
80
+ "maxItems": {"$ref": "#/definitions/nonNegativeInteger"},
81
+ "minItems": {"$ref": "#/definitions/nonNegativeIntegerDefault0"},
82
+ "uniqueItems": {
83
+ "type": "boolean",
84
+ "default": false
85
+ },
86
+ "contains": {"$ref": "#"},
87
+ "maxProperties": {"$ref": "#/definitions/nonNegativeInteger"},
88
+ "minProperties": {"$ref": "#/definitions/nonNegativeIntegerDefault0"},
89
+ "required": {"$ref": "#/definitions/stringArray"},
90
+ "additionalProperties": {"$ref": "#"},
91
+ "definitions": {
92
+ "type": "object",
93
+ "additionalProperties": {"$ref": "#"},
94
+ "default": {}
95
+ },
96
+ "properties": {
97
+ "type": "object",
98
+ "additionalProperties": {"$ref": "#"},
99
+ "default": {}
100
+ },
101
+ "patternProperties": {
102
+ "type": "object",
103
+ "additionalProperties": {"$ref": "#"},
104
+ "default": {}
105
+ },
106
+ "dependencies": {
107
+ "type": "object",
108
+ "additionalProperties": {
109
+ "anyOf": [{"$ref": "#"}, {"$ref": "#/definitions/stringArray"}]
110
+ }
111
+ },
112
+ "propertyNames": {"$ref": "#"},
113
+ "const": {},
114
+ "enum": {
115
+ "type": "array",
116
+ "minItems": 1,
117
+ "uniqueItems": true
118
+ },
119
+ "type": {
120
+ "anyOf": [
121
+ {"$ref": "#/definitions/simpleTypes"},
122
+ {
123
+ "type": "array",
124
+ "items": {"$ref": "#/definitions/simpleTypes"},
125
+ "minItems": 1,
126
+ "uniqueItems": true
127
+ }
128
+ ]
129
+ },
130
+ "format": {"type": "string"},
131
+ "allOf": {"$ref": "#/definitions/schemaArray"},
132
+ "anyOf": {"$ref": "#/definitions/schemaArray"},
133
+ "oneOf": {"$ref": "#/definitions/schemaArray"},
134
+ "not": {"$ref": "#"}
135
+ },
136
+ "default": {}
137
+ }
platform/aiml/elizabeth/e-1-first_session/claude-code-router/node_modules/ajv/lib/refs/json-schema-draft-07.json ADDED
@@ -0,0 +1,151 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "$schema": "http://json-schema.org/draft-07/schema#",
3
+ "$id": "http://json-schema.org/draft-07/schema#",
4
+ "title": "Core schema meta-schema",
5
+ "definitions": {
6
+ "schemaArray": {
7
+ "type": "array",
8
+ "minItems": 1,
9
+ "items": {"$ref": "#"}
10
+ },
11
+ "nonNegativeInteger": {
12
+ "type": "integer",
13
+ "minimum": 0
14
+ },
15
+ "nonNegativeIntegerDefault0": {
16
+ "allOf": [{"$ref": "#/definitions/nonNegativeInteger"}, {"default": 0}]
17
+ },
18
+ "simpleTypes": {
19
+ "enum": ["array", "boolean", "integer", "null", "number", "object", "string"]
20
+ },
21
+ "stringArray": {
22
+ "type": "array",
23
+ "items": {"type": "string"},
24
+ "uniqueItems": true,
25
+ "default": []
26
+ }
27
+ },
28
+ "type": ["object", "boolean"],
29
+ "properties": {
30
+ "$id": {
31
+ "type": "string",
32
+ "format": "uri-reference"
33
+ },
34
+ "$schema": {
35
+ "type": "string",
36
+ "format": "uri"
37
+ },
38
+ "$ref": {
39
+ "type": "string",
40
+ "format": "uri-reference"
41
+ },
42
+ "$comment": {
43
+ "type": "string"
44
+ },
45
+ "title": {
46
+ "type": "string"
47
+ },
48
+ "description": {
49
+ "type": "string"
50
+ },
51
+ "default": true,
52
+ "readOnly": {
53
+ "type": "boolean",
54
+ "default": false
55
+ },
56
+ "examples": {
57
+ "type": "array",
58
+ "items": true
59
+ },
60
+ "multipleOf": {
61
+ "type": "number",
62
+ "exclusiveMinimum": 0
63
+ },
64
+ "maximum": {
65
+ "type": "number"
66
+ },
67
+ "exclusiveMaximum": {
68
+ "type": "number"
69
+ },
70
+ "minimum": {
71
+ "type": "number"
72
+ },
73
+ "exclusiveMinimum": {
74
+ "type": "number"
75
+ },
76
+ "maxLength": {"$ref": "#/definitions/nonNegativeInteger"},
77
+ "minLength": {"$ref": "#/definitions/nonNegativeIntegerDefault0"},
78
+ "pattern": {
79
+ "type": "string",
80
+ "format": "regex"
81
+ },
82
+ "additionalItems": {"$ref": "#"},
83
+ "items": {
84
+ "anyOf": [{"$ref": "#"}, {"$ref": "#/definitions/schemaArray"}],
85
+ "default": true
86
+ },
87
+ "maxItems": {"$ref": "#/definitions/nonNegativeInteger"},
88
+ "minItems": {"$ref": "#/definitions/nonNegativeIntegerDefault0"},
89
+ "uniqueItems": {
90
+ "type": "boolean",
91
+ "default": false
92
+ },
93
+ "contains": {"$ref": "#"},
94
+ "maxProperties": {"$ref": "#/definitions/nonNegativeInteger"},
95
+ "minProperties": {"$ref": "#/definitions/nonNegativeIntegerDefault0"},
96
+ "required": {"$ref": "#/definitions/stringArray"},
97
+ "additionalProperties": {"$ref": "#"},
98
+ "definitions": {
99
+ "type": "object",
100
+ "additionalProperties": {"$ref": "#"},
101
+ "default": {}
102
+ },
103
+ "properties": {
104
+ "type": "object",
105
+ "additionalProperties": {"$ref": "#"},
106
+ "default": {}
107
+ },
108
+ "patternProperties": {
109
+ "type": "object",
110
+ "additionalProperties": {"$ref": "#"},
111
+ "propertyNames": {"format": "regex"},
112
+ "default": {}
113
+ },
114
+ "dependencies": {
115
+ "type": "object",
116
+ "additionalProperties": {
117
+ "anyOf": [{"$ref": "#"}, {"$ref": "#/definitions/stringArray"}]
118
+ }
119
+ },
120
+ "propertyNames": {"$ref": "#"},
121
+ "const": true,
122
+ "enum": {
123
+ "type": "array",
124
+ "items": true,
125
+ "minItems": 1,
126
+ "uniqueItems": true
127
+ },
128
+ "type": {
129
+ "anyOf": [
130
+ {"$ref": "#/definitions/simpleTypes"},
131
+ {
132
+ "type": "array",
133
+ "items": {"$ref": "#/definitions/simpleTypes"},
134
+ "minItems": 1,
135
+ "uniqueItems": true
136
+ }
137
+ ]
138
+ },
139
+ "format": {"type": "string"},
140
+ "contentMediaType": {"type": "string"},
141
+ "contentEncoding": {"type": "string"},
142
+ "if": {"$ref": "#"},
143
+ "then": {"$ref": "#"},
144
+ "else": {"$ref": "#"},
145
+ "allOf": {"$ref": "#/definitions/schemaArray"},
146
+ "anyOf": {"$ref": "#/definitions/schemaArray"},
147
+ "oneOf": {"$ref": "#/definitions/schemaArray"},
148
+ "not": {"$ref": "#"}
149
+ },
150
+ "default": true
151
+ }
platform/aiml/elizabeth/e-1-first_session/claude-code-router/node_modules/ajv/lib/refs/json-schema-secure.json ADDED
@@ -0,0 +1,88 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "$schema": "http://json-schema.org/draft-07/schema#",
3
+ "$id": "https://raw.githubusercontent.com/ajv-validator/ajv/master/lib/refs/json-schema-secure.json#",
4
+ "title": "Meta-schema for the security assessment of JSON Schemas",
5
+ "description": "If a JSON AnySchema fails validation against this meta-schema, it may be unsafe to validate untrusted data",
6
+ "definitions": {
7
+ "schemaArray": {
8
+ "type": "array",
9
+ "minItems": 1,
10
+ "items": {"$ref": "#"}
11
+ }
12
+ },
13
+ "dependencies": {
14
+ "patternProperties": {
15
+ "description": "prevent slow validation of large property names",
16
+ "required": ["propertyNames"],
17
+ "properties": {
18
+ "propertyNames": {
19
+ "required": ["maxLength"]
20
+ }
21
+ }
22
+ },
23
+ "uniqueItems": {
24
+ "description": "prevent slow validation of large non-scalar arrays",
25
+ "if": {
26
+ "properties": {
27
+ "uniqueItems": {"const": true},
28
+ "items": {
29
+ "properties": {
30
+ "type": {
31
+ "anyOf": [
32
+ {
33
+ "enum": ["object", "array"]
34
+ },
35
+ {
36
+ "type": "array",
37
+ "contains": {"enum": ["object", "array"]}
38
+ }
39
+ ]
40
+ }
41
+ }
42
+ }
43
+ }
44
+ },
45
+ "then": {
46
+ "required": ["maxItems"]
47
+ }
48
+ },
49
+ "pattern": {
50
+ "description": "prevent slow pattern matching of large strings",
51
+ "required": ["maxLength"]
52
+ },
53
+ "format": {
54
+ "description": "prevent slow format validation of large strings",
55
+ "required": ["maxLength"]
56
+ }
57
+ },
58
+ "properties": {
59
+ "additionalItems": {"$ref": "#"},
60
+ "additionalProperties": {"$ref": "#"},
61
+ "dependencies": {
62
+ "additionalProperties": {
63
+ "anyOf": [{"type": "array"}, {"$ref": "#"}]
64
+ }
65
+ },
66
+ "items": {
67
+ "anyOf": [{"$ref": "#"}, {"$ref": "#/definitions/schemaArray"}]
68
+ },
69
+ "definitions": {
70
+ "additionalProperties": {"$ref": "#"}
71
+ },
72
+ "patternProperties": {
73
+ "additionalProperties": {"$ref": "#"}
74
+ },
75
+ "properties": {
76
+ "additionalProperties": {"$ref": "#"}
77
+ },
78
+ "if": {"$ref": "#"},
79
+ "then": {"$ref": "#"},
80
+ "else": {"$ref": "#"},
81
+ "allOf": {"$ref": "#/definitions/schemaArray"},
82
+ "anyOf": {"$ref": "#/definitions/schemaArray"},
83
+ "oneOf": {"$ref": "#/definitions/schemaArray"},
84
+ "not": {"$ref": "#"},
85
+ "contains": {"$ref": "#"},
86
+ "propertyNames": {"$ref": "#"}
87
+ }
88
+ }
platform/aiml/elizabeth/e-1-first_session/claude-code-router/node_modules/ajv/lib/refs/jtd-schema.ts ADDED
@@ -0,0 +1,130 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import {SchemaObject} from "../types"
2
+
3
+ type MetaSchema = (root: boolean) => SchemaObject
4
+
5
+ const shared: MetaSchema = (root) => {
6
+ const sch: SchemaObject = {
7
+ nullable: {type: "boolean"},
8
+ metadata: {
9
+ optionalProperties: {
10
+ union: {elements: {ref: "schema"}},
11
+ },
12
+ additionalProperties: true,
13
+ },
14
+ }
15
+ if (root) sch.definitions = {values: {ref: "schema"}}
16
+ return sch
17
+ }
18
+
19
+ const emptyForm: MetaSchema = (root) => ({
20
+ optionalProperties: shared(root),
21
+ })
22
+
23
+ const refForm: MetaSchema = (root) => ({
24
+ properties: {
25
+ ref: {type: "string"},
26
+ },
27
+ optionalProperties: shared(root),
28
+ })
29
+
30
+ const typeForm: MetaSchema = (root) => ({
31
+ properties: {
32
+ type: {
33
+ enum: [
34
+ "boolean",
35
+ "timestamp",
36
+ "string",
37
+ "float32",
38
+ "float64",
39
+ "int8",
40
+ "uint8",
41
+ "int16",
42
+ "uint16",
43
+ "int32",
44
+ "uint32",
45
+ ],
46
+ },
47
+ },
48
+ optionalProperties: shared(root),
49
+ })
50
+
51
+ const enumForm: MetaSchema = (root) => ({
52
+ properties: {
53
+ enum: {elements: {type: "string"}},
54
+ },
55
+ optionalProperties: shared(root),
56
+ })
57
+
58
+ const elementsForm: MetaSchema = (root) => ({
59
+ properties: {
60
+ elements: {ref: "schema"},
61
+ },
62
+ optionalProperties: shared(root),
63
+ })
64
+
65
+ const propertiesForm: MetaSchema = (root) => ({
66
+ properties: {
67
+ properties: {values: {ref: "schema"}},
68
+ },
69
+ optionalProperties: {
70
+ optionalProperties: {values: {ref: "schema"}},
71
+ additionalProperties: {type: "boolean"},
72
+ ...shared(root),
73
+ },
74
+ })
75
+
76
+ const optionalPropertiesForm: MetaSchema = (root) => ({
77
+ properties: {
78
+ optionalProperties: {values: {ref: "schema"}},
79
+ },
80
+ optionalProperties: {
81
+ additionalProperties: {type: "boolean"},
82
+ ...shared(root),
83
+ },
84
+ })
85
+
86
+ const discriminatorForm: MetaSchema = (root) => ({
87
+ properties: {
88
+ discriminator: {type: "string"},
89
+ mapping: {
90
+ values: {
91
+ metadata: {
92
+ union: [propertiesForm(false), optionalPropertiesForm(false)],
93
+ },
94
+ },
95
+ },
96
+ },
97
+ optionalProperties: shared(root),
98
+ })
99
+
100
+ const valuesForm: MetaSchema = (root) => ({
101
+ properties: {
102
+ values: {ref: "schema"},
103
+ },
104
+ optionalProperties: shared(root),
105
+ })
106
+
107
+ const schema: MetaSchema = (root) => ({
108
+ metadata: {
109
+ union: [
110
+ emptyForm,
111
+ refForm,
112
+ typeForm,
113
+ enumForm,
114
+ elementsForm,
115
+ propertiesForm,
116
+ optionalPropertiesForm,
117
+ discriminatorForm,
118
+ valuesForm,
119
+ ].map((s) => s(root)),
120
+ },
121
+ })
122
+
123
+ const jtdMetaSchema: SchemaObject = {
124
+ definitions: {
125
+ schema: schema(false),
126
+ },
127
+ ...schema(true),
128
+ }
129
+
130
+ export default jtdMetaSchema
platform/aiml/elizabeth/e-1-first_session/claude-code-router/node_modules/ajv/lib/runtime/equal.ts ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ // https://github.com/ajv-validator/ajv/issues/889
2
+ import * as equal from "fast-deep-equal"
3
+
4
+ type Equal = typeof equal & {code: string}
5
+ ;(equal as Equal).code = 'require("ajv/dist/runtime/equal").default'
6
+
7
+ export default equal as Equal
platform/aiml/elizabeth/e-1-first_session/claude-code-router/node_modules/ajv/lib/runtime/parseJson.ts ADDED
@@ -0,0 +1,177 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ const rxParseJson = /position\s(\d+)(?: \(line \d+ column \d+\))?$/
2
+
3
+ export function parseJson(s: string, pos: number): unknown {
4
+ let endPos: number | undefined
5
+ parseJson.message = undefined
6
+ let matches: RegExpExecArray | null
7
+ if (pos) s = s.slice(pos)
8
+ try {
9
+ parseJson.position = pos + s.length
10
+ return JSON.parse(s)
11
+ } catch (e) {
12
+ matches = rxParseJson.exec((e as Error).message)
13
+ if (!matches) {
14
+ parseJson.message = "unexpected end"
15
+ return undefined
16
+ }
17
+ endPos = +matches[1]
18
+ const c = s[endPos]
19
+ s = s.slice(0, endPos)
20
+ parseJson.position = pos + endPos
21
+ try {
22
+ return JSON.parse(s)
23
+ } catch (e1) {
24
+ parseJson.message = `unexpected token ${c}`
25
+ return undefined
26
+ }
27
+ }
28
+ }
29
+
30
+ parseJson.message = undefined as string | undefined
31
+ parseJson.position = 0 as number
32
+ parseJson.code = 'require("ajv/dist/runtime/parseJson").parseJson'
33
+
34
+ export function parseJsonNumber(s: string, pos: number, maxDigits?: number): number | undefined {
35
+ let numStr = ""
36
+ let c: string
37
+ parseJsonNumber.message = undefined
38
+ if (s[pos] === "-") {
39
+ numStr += "-"
40
+ pos++
41
+ }
42
+ if (s[pos] === "0") {
43
+ numStr += "0"
44
+ pos++
45
+ } else {
46
+ if (!parseDigits(maxDigits)) {
47
+ errorMessage()
48
+ return undefined
49
+ }
50
+ }
51
+ if (maxDigits) {
52
+ parseJsonNumber.position = pos
53
+ return +numStr
54
+ }
55
+ if (s[pos] === ".") {
56
+ numStr += "."
57
+ pos++
58
+ if (!parseDigits()) {
59
+ errorMessage()
60
+ return undefined
61
+ }
62
+ }
63
+ if (((c = s[pos]), c === "e" || c === "E")) {
64
+ numStr += "e"
65
+ pos++
66
+ if (((c = s[pos]), c === "+" || c === "-")) {
67
+ numStr += c
68
+ pos++
69
+ }
70
+ if (!parseDigits()) {
71
+ errorMessage()
72
+ return undefined
73
+ }
74
+ }
75
+ parseJsonNumber.position = pos
76
+ return +numStr
77
+
78
+ function parseDigits(maxLen?: number): boolean {
79
+ let digit = false
80
+ while (((c = s[pos]), c >= "0" && c <= "9" && (maxLen === undefined || maxLen-- > 0))) {
81
+ digit = true
82
+ numStr += c
83
+ pos++
84
+ }
85
+ return digit
86
+ }
87
+
88
+ function errorMessage(): void {
89
+ parseJsonNumber.position = pos
90
+ parseJsonNumber.message = pos < s.length ? `unexpected token ${s[pos]}` : "unexpected end"
91
+ }
92
+ }
93
+
94
+ parseJsonNumber.message = undefined as string | undefined
95
+ parseJsonNumber.position = 0 as number
96
+ parseJsonNumber.code = 'require("ajv/dist/runtime/parseJson").parseJsonNumber'
97
+
98
+ const escapedChars: {[X in string]?: string} = {
99
+ b: "\b",
100
+ f: "\f",
101
+ n: "\n",
102
+ r: "\r",
103
+ t: "\t",
104
+ '"': '"',
105
+ "/": "/",
106
+ "\\": "\\",
107
+ }
108
+
109
+ const CODE_A: number = "a".charCodeAt(0)
110
+ const CODE_0: number = "0".charCodeAt(0)
111
+
112
+ export function parseJsonString(s: string, pos: number): string | undefined {
113
+ let str = ""
114
+ let c: string | undefined
115
+ parseJsonString.message = undefined
116
+ // eslint-disable-next-line no-constant-condition, @typescript-eslint/no-unnecessary-condition
117
+ while (true) {
118
+ c = s[pos++]
119
+ if (c === '"') break
120
+ if (c === "\\") {
121
+ c = s[pos]
122
+ if (c in escapedChars) {
123
+ str += escapedChars[c]
124
+ pos++
125
+ } else if (c === "u") {
126
+ pos++
127
+ let count = 4
128
+ let code = 0
129
+ while (count--) {
130
+ code <<= 4
131
+ c = s[pos]
132
+ // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
133
+ if (c === undefined) {
134
+ errorMessage("unexpected end")
135
+ return undefined
136
+ }
137
+ c = c.toLowerCase()
138
+ if (c >= "a" && c <= "f") {
139
+ code += c.charCodeAt(0) - CODE_A + 10
140
+ } else if (c >= "0" && c <= "9") {
141
+ code += c.charCodeAt(0) - CODE_0
142
+ } else {
143
+ errorMessage(`unexpected token ${c}`)
144
+ return undefined
145
+ }
146
+ pos++
147
+ }
148
+ str += String.fromCharCode(code)
149
+ } else {
150
+ errorMessage(`unexpected token ${c}`)
151
+ return undefined
152
+ }
153
+ // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
154
+ } else if (c === undefined) {
155
+ errorMessage("unexpected end")
156
+ return undefined
157
+ } else {
158
+ if (c.charCodeAt(0) >= 0x20) {
159
+ str += c
160
+ } else {
161
+ errorMessage(`unexpected token ${c}`)
162
+ return undefined
163
+ }
164
+ }
165
+ }
166
+ parseJsonString.position = pos
167
+ return str
168
+
169
+ function errorMessage(msg: string): void {
170
+ parseJsonString.position = pos
171
+ parseJsonString.message = msg
172
+ }
173
+ }
174
+
175
+ parseJsonString.message = undefined as string | undefined
176
+ parseJsonString.position = 0 as number
177
+ parseJsonString.code = 'require("ajv/dist/runtime/parseJson").parseJsonString'
platform/aiml/elizabeth/e-1-first_session/claude-code-router/node_modules/ajv/lib/runtime/quote.ts ADDED
@@ -0,0 +1,31 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ const rxEscapable =
2
+ // eslint-disable-next-line no-control-regex, no-misleading-character-class
3
+ /[\\"\u0000-\u001f\u007f-\u009f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g
4
+
5
+ const escaped: {[K in string]?: string} = {
6
+ "\b": "\\b",
7
+ "\t": "\\t",
8
+ "\n": "\\n",
9
+ "\f": "\\f",
10
+ "\r": "\\r",
11
+ '"': '\\"',
12
+ "\\": "\\\\",
13
+ }
14
+
15
+ export default function quote(s: string): string {
16
+ rxEscapable.lastIndex = 0
17
+ return (
18
+ '"' +
19
+ (rxEscapable.test(s)
20
+ ? s.replace(rxEscapable, (a) => {
21
+ const c = escaped[a]
22
+ return typeof c === "string"
23
+ ? c
24
+ : "\\u" + ("0000" + a.charCodeAt(0).toString(16)).slice(-4)
25
+ })
26
+ : s) +
27
+ '"'
28
+ )
29
+ }
30
+
31
+ quote.code = 'require("ajv/dist/runtime/quote").default'
platform/aiml/elizabeth/e-1-first_session/claude-code-router/node_modules/ajv/lib/runtime/re2.ts ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ import * as re2 from "re2"
2
+
3
+ type Re2 = typeof re2 & {code: string}
4
+ ;(re2 as Re2).code = 'require("ajv/dist/runtime/re2").default'
5
+
6
+ export default re2 as Re2
platform/aiml/elizabeth/e-1-first_session/claude-code-router/node_modules/ajv/lib/runtime/timestamp.ts ADDED
@@ -0,0 +1,46 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ const DT_SEPARATOR = /t|\s/i
2
+ const DATE = /^(\d\d\d\d)-(\d\d)-(\d\d)$/
3
+ const TIME = /^(\d\d):(\d\d):(\d\d)(?:\.\d+)?(?:z|([+-]\d\d)(?::?(\d\d))?)$/i
4
+ const DAYS = [0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
5
+
6
+ export default function validTimestamp(str: string, allowDate: boolean): boolean {
7
+ // http://tools.ietf.org/html/rfc3339#section-5.6
8
+ const dt: string[] = str.split(DT_SEPARATOR)
9
+ return (
10
+ (dt.length === 2 && validDate(dt[0]) && validTime(dt[1])) ||
11
+ (allowDate && dt.length === 1 && validDate(dt[0]))
12
+ )
13
+ }
14
+
15
+ function validDate(str: string): boolean {
16
+ const matches: string[] | null = DATE.exec(str)
17
+ if (!matches) return false
18
+ const y: number = +matches[1]
19
+ const m: number = +matches[2]
20
+ const d: number = +matches[3]
21
+ return (
22
+ m >= 1 &&
23
+ m <= 12 &&
24
+ d >= 1 &&
25
+ (d <= DAYS[m] ||
26
+ // leap year: https://tools.ietf.org/html/rfc3339#appendix-C
27
+ (m === 2 && d === 29 && (y % 100 === 0 ? y % 400 === 0 : y % 4 === 0)))
28
+ )
29
+ }
30
+
31
+ function validTime(str: string): boolean {
32
+ const matches: string[] | null = TIME.exec(str)
33
+ if (!matches) return false
34
+ const hr: number = +matches[1]
35
+ const min: number = +matches[2]
36
+ const sec: number = +matches[3]
37
+ const tzH: number = +(matches[4] || 0)
38
+ const tzM: number = +(matches[5] || 0)
39
+ return (
40
+ (hr <= 23 && min <= 59 && sec <= 59) ||
41
+ // leap second
42
+ (hr - tzH === 23 && min - tzM === 59 && sec === 60)
43
+ )
44
+ }
45
+
46
+ validTimestamp.code = 'require("ajv/dist/runtime/timestamp").default'
platform/aiml/elizabeth/e-1-first_session/claude-code-router/node_modules/ajv/lib/runtime/ucs2length.ts ADDED
@@ -0,0 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // https://mathiasbynens.be/notes/javascript-encoding
2
+ // https://github.com/bestiejs/punycode.js - punycode.ucs2.decode
3
+ export default function ucs2length(str: string): number {
4
+ const len = str.length
5
+ let length = 0
6
+ let pos = 0
7
+ let value: number
8
+ while (pos < len) {
9
+ length++
10
+ value = str.charCodeAt(pos++)
11
+ if (value >= 0xd800 && value <= 0xdbff && pos < len) {
12
+ // high surrogate, and there is a next character
13
+ value = str.charCodeAt(pos)
14
+ if ((value & 0xfc00) === 0xdc00) pos++ // low surrogate
15
+ }
16
+ }
17
+ return length
18
+ }
19
+
20
+ ucs2length.code = 'require("ajv/dist/runtime/ucs2length").default'
platform/aiml/elizabeth/e-1-first_session/claude-code-router/node_modules/ajv/lib/runtime/uri.ts ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ import * as uri from "fast-uri"
2
+
3
+ type URI = typeof uri & {code: string}
4
+ ;(uri as URI).code = 'require("ajv/dist/runtime/uri").default'
5
+
6
+ export default uri as URI
platform/aiml/elizabeth/e-1-first_session/claude-code-router/node_modules/ajv/lib/runtime/validation_error.ts ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import type {ErrorObject} from "../types"
2
+
3
+ export default class ValidationError extends Error {
4
+ readonly errors: Partial<ErrorObject>[]
5
+ readonly ajv: true
6
+ readonly validation: true
7
+
8
+ constructor(errors: Partial<ErrorObject>[]) {
9
+ super("validation failed")
10
+ this.errors = errors
11
+ this.ajv = this.validation = true
12
+ }
13
+ }