@zeronsh/orbit 0.3.2 → 0.3.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{chunk-G6NWZNQR.js → chunk-KFX7HOCV.js} +3 -3
- package/dist/{chunk-G6NWZNQR.js.map → chunk-KFX7HOCV.js.map} +1 -1
- package/dist/{chunk-EX4WSUC3.js → chunk-LUFJQUF4.js} +79 -7
- package/dist/chunk-LUFJQUF4.js.map +1 -0
- package/dist/{chunk-PSGVTMOB.js → chunk-RP6SPOCI.js} +3 -3
- package/dist/{chunk-PSGVTMOB.js.map → chunk-RP6SPOCI.js.map} +1 -1
- package/dist/client.d.ts +11 -0
- package/dist/client.js +1 -1
- package/dist/drizzle/cli/bin.js +3 -3
- package/dist/drizzle/cli.js +3 -3
- package/dist/drizzle.js +2 -2
- package/dist/orm-core.js +2 -2
- package/dist/server.js +1 -1
- package/package.json +1 -1
- package/dist/chunk-EX4WSUC3.js.map +0 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { table, relationships, createSchema, number, boolean, json, string, optional } from './chunk-
|
|
1
|
+
import { table, relationships, createSchema, number, boolean, json, string, optional } from './chunk-LUFJQUF4.js';
|
|
2
2
|
|
|
3
3
|
// orm-core/src/adapter.ts
|
|
4
4
|
function defineAdapter(adapter) {
|
|
@@ -249,5 +249,5 @@ function emitSchema(ir, options = {}) {
|
|
|
249
249
|
}
|
|
250
250
|
|
|
251
251
|
export { buildOrbitSchema, defineAdapter, emitSchema };
|
|
252
|
-
//# sourceMappingURL=chunk-
|
|
253
|
-
//# sourceMappingURL=chunk-
|
|
252
|
+
//# sourceMappingURL=chunk-KFX7HOCV.js.map
|
|
253
|
+
//# sourceMappingURL=chunk-KFX7HOCV.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../orm-core/src/adapter.ts","../orm-core/src/build.ts","../orm-core/src/emit.ts"],"names":[],"mappings":";;;AAoBO,SAAS,cAA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AAAA,IAC1E;AAAA,EACF;AAEA,EAAA,OAAO,KAAA,CAAM,IAAA,CAAK,IAAI,CAAA,GAAI,IAAA;AAC5B","file":"chunk-G6NWZNQR.js","sourcesContent":["// The adapter contract. An ORM adapter converts its native schema into the\n// {@link SchemaIR}. That's the entire surface a new ORM has to implement —\n// everything downstream (runtime build + codegen) is shared.\n\nimport type { SchemaIR } from './ir.ts';\n\n/**\n * Converts an ORM's native schema (`Input`) into Orbit's normalized {@link SchemaIR}.\n *\n * @typeParam Input the ORM's schema object (e.g. a Drizzle `* as schema` import).\n * @typeParam Config adapter-specific options (table/column selection, casing, …).\n */\nexport interface OrmAdapter<Input = unknown, Config = unknown> {\n /** Stable adapter id, e.g. `'drizzle'`. Used in generated-file headers. */\n readonly name: string;\n /** Produce the normalized IR for the given schema + options. */\n toIR(input: Input, config?: Config): SchemaIR;\n}\n\n/** Helper to define an adapter with inferred generics. */\nexport function defineAdapter<Input, Config>(adapter: OrmAdapter<Input, Config>): OrmAdapter<Input, Config> {\n return adapter;\n}\n","// Runtime: turn a {@link SchemaIR} into a live Orbit `SchemaDef` (the same object\n// `createSchema(...)` would produce). Used by adapters' `defineOrbitSchema(...)`\n// runtime entry point. Custom `$type<>()` types are type-level only and do not\n// exist at runtime, so this produces the plain column types; for full custom-type\n// fidelity, use the codegen emitter (`emit.ts`) instead.\n\nimport {\n boolean as boolCol,\n createSchema,\n json as jsonCol,\n number as numCol,\n optional,\n relationships,\n string as strCol,\n table,\n type Column,\n type RelationshipsDef,\n type SchemaDef,\n type TableDef,\n} from '../../client/src/index.ts';\nimport type { IRColumn, IRRelationship, SchemaIR } from './ir.ts';\n\nfunction makeColumn(c: IRColumn): Column {\n const base =\n c.type === 'number' ? numCol() : c.type === 'boolean' ? boolCol() : c.type === 'json' ? jsonCol() : strCol();\n return c.optional ? optional(base as Column) : (base as Column);\n}\n\n/** Build a live Orbit schema object from the IR. */\nexport function buildOrbitSchema(ir: SchemaIR): SchemaDef {\n const tableDefs = new Map<string, TableDef>();\n const tables: TableDef[] = [];\n\n for (const t of ir.tables) {\n const columns: Record<string, Column> = {};\n for (const c of t.columns) columns[c.name] = makeColumn(c);\n const pk = (t.primaryKey.length ? t.primaryKey : ['id']) as [string, ...string[]];\n const def = table(t.name)\n .columns(columns as never)\n .primaryKey(...pk) as unknown as TableDef;\n tableDefs.set(t.name, def);\n tables.push(def);\n }\n\n // `relationships()` is per source table, and `createSchema` rejects a table\n // whose relationships are declared twice — so group all of a table's\n // relationships into one call.\n const byTable = new Map<string, IRRelationship[]>();\n for (const r of ir.relationships) {\n const list = byTable.get(r.table) ?? [];\n list.push(r);\n byTable.set(r.table, list);\n }\n\n const rels: RelationshipsDef[] = [];\n for (const [tableName, list] of byTable) {\n const src = tableDefs.get(tableName);\n if (!src) continue;\n rels.push(\n relationships(src, ({ one, many }) => {\n const out: Record<string, unknown> = {};\n for (const r of list) {\n const last = r.chain[r.chain.length - 1];\n const connect = last.cardinality === 'one' ? one : many;\n const args = r.chain.map((c) => {\n const dest = tableDefs.get(c.destSchema);\n if (!dest) throw new Error(`@orbit/orm-core: relationship \"${tableName}.${r.name}\" references unknown table \"${c.destSchema}\"`);\n return { sourceField: [...c.sourceField], destField: [...c.destField], destSchema: dest };\n });\n // `one`/`many` accept 1 (direct) or 2 (junction) hops.\n out[r.name] = (connect as (...a: unknown[]) => unknown)(...args);\n }\n return out as never;\n }),\n );\n }\n\n return createSchema({ tables: tables as never, relationships: rels as never });\n}\n","// Codegen: turn a {@link SchemaIR} into Orbit-schema TypeScript *source*. Unlike\n// the runtime builder, this preserves each column's custom `$type<>()` and enum\n// types (emitted as `string<...>()` / `json<...>()`), so the generated schema is\n// fully typed. Output is plain text; the CLI optionally runs Prettier over it.\n\nimport type { IRColumn, IRRelationship, IRTable, SchemaIR } from './ir.ts';\n\nexport interface EmitOptions {\n /** Module the Orbit schema helpers are imported from. Default `@orbit/client`. */\n readonly importFrom?: string;\n /** Append `.js` to the import (Node16/NodeNext ESM). Default false. */\n readonly jsExtension?: boolean;\n /** Exported schema const name. Default `schema`. */\n readonly schemaName?: string;\n /** Also emit `export type <Table> = RowOf<typeof <table>>` for each table. Default true. */\n readonly rowTypes?: boolean;\n /** Header comment lines (without leading `//`). */\n readonly header?: readonly string[];\n /**\n * Extra `import type { ... } from '...'` lines to prepend — used to bring in the\n * named TypeScript types referenced by resolved custom column types (e.g. a\n * `jsonb().$type<PostMeta>()` resolves to `PostMeta`, imported from the schema).\n */\n readonly typeImports?: readonly { readonly module: string; readonly names: readonly string[] }[];\n}\n\nconst RESERVED = new Set([\n 'break', 'case', 'catch', 'class', 'const', 'continue', 'debugger', 'default', 'delete', 'do', 'else',\n 'export', 'extends', 'false', 'finally', 'for', 'function', 'if', 'import', 'in', 'instanceof', 'new',\n 'null', 'return', 'super', 'switch', 'this', 'throw', 'true', 'try', 'typeof', 'var', 'void', 'while',\n 'with', 'yield', 'let', 'static', 'enum', 'await', 'implements', 'package', 'protected', 'interface',\n 'private', 'public', 'schema', 'table', 'string', 'number', 'boolean', 'json', 'optional', 'createSchema',\n 'relationships', 'RowOf', 'one', 'many',\n]);\n\nconst IDENT_RE = /^[A-Za-z_$][A-Za-z0-9_$]*$/;\n\nfunction isValidIdent(s: string): boolean {\n return IDENT_RE.test(s);\n}\n\n/** A stable, collision-free identifier for each table name (used as the const). */\nfunction tableIdentifiers(tables: readonly IRTable[]): Map<string, string> {\n const out = new Map<string, string>();\n const used = new Set<string>();\n for (const t of tables) {\n let base = t.name.replace(/[^A-Za-z0-9_$]/g, '_');\n if (!IDENT_RE.test(base) || base.startsWith('_') === false && /^[0-9]/.test(base)) base = `t_${base}`;\n if (RESERVED.has(base)) base = `${base}_`;\n let ident = base;\n let i = 2;\n while (used.has(ident)) ident = `${base}${i++}`;\n used.add(ident);\n out.set(t.name, ident);\n }\n return out;\n}\n\nfunction pascal(name: string): string {\n return name\n .split(/[^A-Za-z0-9]+/)\n .filter(Boolean)\n .map((p) => p.charAt(0).toUpperCase() + p.slice(1))\n .join('') || 'Row';\n}\n\nfunction keyLiteral(name: string): string {\n return isValidIdent(name) && !RESERVED.has(name) ? name : JSON.stringify(name);\n}\n\nfunction fieldArray(fields: readonly string[]): string {\n return `[${fields.map((f) => JSON.stringify(f)).join(', ')}]`;\n}\n\nfunction columnExpr(c: IRColumn): string {\n const generic = c.customType ? `<${c.customType}>` : '';\n const call = `${c.type}${generic}()`;\n return c.optional ? `optional(${call})` : call;\n}\n\nfunction emitTable(t: IRTable, ident: string): string {\n const cols = t.columns.map((c) => ` ${keyLiteral(c.name)}: ${columnExpr(c)},`).join('\\n');\n const pk = (t.primaryKey.length ? t.primaryKey : ['id']).map((k) => JSON.stringify(k)).join(', ');\n return `const ${ident} = table(${JSON.stringify(t.name)})\\n .columns({\\n${cols}\\n })\\n .primaryKey(${pk});`;\n}\n\nfunction emitRelationshipsBlock(\n tableName: string,\n rels: readonly IRRelationship[],\n idents: Map<string, string>,\n): string {\n const srcIdent = idents.get(tableName)!;\n const entries = rels\n .map((r) => {\n const last = r.chain[r.chain.length - 1];\n const fn = last.cardinality === 'one' ? 'one' : 'many';\n const hops = r.chain.map((c) => {\n const destIdent = idents.get(c.destSchema);\n if (!destIdent) throw new Error(`@orbit/orm-core: relationship \"${tableName}.${r.name}\" references unknown table \"${c.destSchema}\"`);\n return `{ sourceField: ${fieldArray(c.sourceField)}, destField: ${fieldArray(c.destField)}, destSchema: ${destIdent} }`;\n });\n const body = hops.length === 1 ? `${fn}(${hops[0]})` : `${fn}(\\n ${hops.join(',\\n ')},\\n )`;\n return ` ${keyLiteral(r.name)}: ${body},`;\n })\n .join('\\n');\n return ` relationships(${srcIdent}, ({ one, many }) => ({\\n${entries}\\n })),`;\n}\n\n/** Emit the full Orbit-schema TypeScript source for an IR. */\nexport function emitSchema(ir: SchemaIR, options: EmitOptions = {}): string {\n const {\n importFrom = '@zeronsh/orbit/client',\n jsExtension = false,\n schemaName = 'schema',\n rowTypes = true,\n header = ['Generated by @orbit/orm-core — do not edit by hand.'],\n } = options;\n\n const idents = tableIdentifiers(ir.tables);\n\n // Which helpers do we actually use?\n const used = new Set<string>(['createSchema', 'table']);\n for (const t of ir.tables) {\n for (const c of t.columns) {\n used.add(c.type);\n if (c.optional) used.add('optional');\n }\n }\n const hasRels = ir.relationships.length > 0;\n if (hasRels) used.add('relationships');\n if (rowTypes) used.add('RowOf');\n\n // `RowOf` is a type-only export; keep it in a separate `import type` for clarity.\n const valueImports = [...used].filter((u) => u !== 'RowOf');\n const order = ['createSchema', 'relationships', 'table', 'string', 'number', 'boolean', 'json', 'optional'];\n valueImports.sort((a, b) => {\n const ia = order.indexOf(a);\n const ib = order.indexOf(b);\n return (ia < 0 ? 99 : ia) - (ib < 0 ? 99 : ib);\n });\n\n const spec = jsExtension ? `${importFrom}` : importFrom; // import path unchanged; subpath rarely needs .js\n const lines: string[] = [];\n\n for (const h of header) lines.push(`// ${h}`);\n if (header.length) lines.push('');\n\n lines.push(`import {`);\n for (const v of valueImports) lines.push(` ${v},`);\n lines.push(`} from ${JSON.stringify(spec)};`);\n if (rowTypes) lines.push(`import type { RowOf } from ${JSON.stringify(spec)};`);\n for (const imp of options.typeImports ?? []) {\n if (imp.names.length) lines.push(`import type { ${[...imp.names].join(', ')} } from ${JSON.stringify(imp.module)};`);\n }\n lines.push('');\n\n // Tables.\n for (const t of ir.tables) {\n lines.push(emitTable(t, idents.get(t.name)!));\n lines.push('');\n }\n\n // Schema.\n const tableList = ir.tables.map((t) => idents.get(t.name)!).join(', ');\n lines.push(`export const ${schemaName} = createSchema({`);\n lines.push(` tables: [${tableList}],`);\n if (hasRels) {\n const byTable = new Map<string, IRRelationship[]>();\n for (const r of ir.relationships) {\n const l = byTable.get(r.table) ?? [];\n l.push(r);\n byTable.set(r.table, l);\n }\n lines.push(` relationships: [`);\n for (const t of ir.tables) {\n const list = byTable.get(t.name);\n if (list && list.length) lines.push(emitRelationshipsBlock(t.name, list, idents));\n }\n lines.push(` ],`);\n }\n lines.push(`});`);\n lines.push('');\n lines.push(`export type ${pascal(schemaName)} = typeof ${schemaName};`);\n\n // Row types.\n if (rowTypes) {\n lines.push('');\n const seen = new Set<string>([pascal(schemaName)]);\n for (const t of ir.tables) {\n let name = pascal(t.name);\n while (seen.has(name)) name = `${name}Row`;\n seen.add(name);\n lines.push(`export type ${name} = RowOf<typeof ${idents.get(t.name)!}>;`);\n }\n }\n\n return lines.join('\\n') + '\\n';\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["../orm-core/src/adapter.ts","../orm-core/src/build.ts","../orm-core/src/emit.ts"],"names":[],"mappings":";;;AAoBO,SAAS,cAA6B,OAAA,EAA+D;AAC1G,EAAA,OAAO,OAAA;AACT;;;ACAA,SAAS,WAAW,CAAA,EAAqB;AACvC,EAAA,MAAM,OACJ,CAAA,CAAE,IAAA,KAAS,QAAA,GAAW,MAAA,KAAW,CAAA,CAAE,IAAA,KAAS,SAAA,GAAY,OAAA,KAAY,CAAA,CAAE,IAAA,KAAS,MAAA,GAAS,IAAA,KAAY,MAAA,EAAO;AAC7G,EAAA,OAAO,CAAA,CAAE,QAAA,GAAW,QAAA,CAAS,IAAc,CAAA,GAAK,IAAA;AAClD;AAGO,SAAS,iBAAiB,EAAA,EAAyB;AACxD,EAAA,MAAM,SAAA,uBAAgB,GAAA,EAAsB;AAC5C,EAAA,MAAM,SAAqB,EAAC;AAE5B,EAAA,KAAA,MAAW,CAAA,IAAK,GAAG,MAAA,EAAQ;AACzB,IAAA,MAAM,UAAkC,EAAC;AACzC,IAAA,KAAA,MAAW,CAAA,IAAK,EAAE,OAAA,EAAS,OAAA,CAAQ,EAAE,IAAI,CAAA,GAAI,WAAW,CAAC,CAAA;AACzD,IAAA,MAAM,KAAM,CAAA,CAAE,UAAA,CAAW,SAAS,CAAA,CAAE,UAAA,GAAa,CAAC,IAAI,CAAA;AACtD,IAAA,MAAM,GAAA,GAAM,KAAA,CAAM,CAAA,CAAE,IAAI,CAAA,CACrB,QAAQ,OAAgB,CAAA,CACxB,UAAA,CA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AW,CAAA,IAAK,GAAG,MAAA,EAAQ;AACzB,MAAA,IAAI,IAAA,GAAO,MAAA,CAAO,CAAA,CAAE,IAAI,CAAA;AACxB,MAAA,OAAO,KAAK,GAAA,CAAI,IAAI,CAAA,EAAG,IAAA,GAAO,GAAG,IAAI,CAAA,GAAA,CAAA;AACrC,MAAA,IAAA,CAAK,IAAI,IAAI,CAAA;AACb,MAAA,KAAA,CAAM,IAAA,CAAK,eAAe,IAAI,CAAA,gBAAA,EAAmB,OAAO,GAAA,CAAI,CAAA,CAAE,IAAI,CAAE,CAAA,EAAA,CAAI,CAAA;AAAA,IAC1E;AAAA,EACF;AAEA,EAAA,OAAO,KAAA,CAAM,IAAA,CAAK,IAAI,CAAA,GAAI,IAAA;AAC5B","file":"chunk-KFX7HOCV.js","sourcesContent":["// The adapter contract. An ORM adapter converts its native schema into the\n// {@link SchemaIR}. That's the entire surface a new ORM has to implement —\n// everything downstream (runtime build + codegen) is shared.\n\nimport type { SchemaIR } from './ir.ts';\n\n/**\n * Converts an ORM's native schema (`Input`) into Orbit's normalized {@link SchemaIR}.\n *\n * @typeParam Input the ORM's schema object (e.g. a Drizzle `* as schema` import).\n * @typeParam Config adapter-specific options (table/column selection, casing, …).\n */\nexport interface OrmAdapter<Input = unknown, Config = unknown> {\n /** Stable adapter id, e.g. `'drizzle'`. Used in generated-file headers. */\n readonly name: string;\n /** Produce the normalized IR for the given schema + options. */\n toIR(input: Input, config?: Config): SchemaIR;\n}\n\n/** Helper to define an adapter with inferred generics. */\nexport function defineAdapter<Input, Config>(adapter: OrmAdapter<Input, Config>): OrmAdapter<Input, Config> {\n return adapter;\n}\n","// Runtime: turn a {@link SchemaIR} into a live Orbit `SchemaDef` (the same object\n// `createSchema(...)` would produce). Used by adapters' `defineOrbitSchema(...)`\n// runtime entry point. Custom `$type<>()` types are type-level only and do not\n// exist at runtime, so this produces the plain column types; for full custom-type\n// fidelity, use the codegen emitter (`emit.ts`) instead.\n\nimport {\n boolean as boolCol,\n createSchema,\n json as jsonCol,\n number as numCol,\n optional,\n relationships,\n string as strCol,\n table,\n type Column,\n type RelationshipsDef,\n type SchemaDef,\n type TableDef,\n} from '../../client/src/index.ts';\nimport type { IRColumn, IRRelationship, SchemaIR } from './ir.ts';\n\nfunction makeColumn(c: IRColumn): Column {\n const base =\n c.type === 'number' ? numCol() : c.type === 'boolean' ? boolCol() : c.type === 'json' ? jsonCol() : strCol();\n return c.optional ? optional(base as Column) : (base as Column);\n}\n\n/** Build a live Orbit schema object from the IR. */\nexport function buildOrbitSchema(ir: SchemaIR): SchemaDef {\n const tableDefs = new Map<string, TableDef>();\n const tables: TableDef[] = [];\n\n for (const t of ir.tables) {\n const columns: Record<string, Column> = {};\n for (const c of t.columns) columns[c.name] = makeColumn(c);\n const pk = (t.primaryKey.length ? t.primaryKey : ['id']) as [string, ...string[]];\n const def = table(t.name)\n .columns(columns as never)\n .primaryKey(...pk) as unknown as TableDef;\n tableDefs.set(t.name, def);\n tables.push(def);\n }\n\n // `relationships()` is per source table, and `createSchema` rejects a table\n // whose relationships are declared twice — so group all of a table's\n // relationships into one call.\n const byTable = new Map<string, IRRelationship[]>();\n for (const r of ir.relationships) {\n const list = byTable.get(r.table) ?? [];\n list.push(r);\n byTable.set(r.table, list);\n }\n\n const rels: RelationshipsDef[] = [];\n for (const [tableName, list] of byTable) {\n const src = tableDefs.get(tableName);\n if (!src) continue;\n rels.push(\n relationships(src, ({ one, many }) => {\n const out: Record<string, unknown> = {};\n for (const r of list) {\n const last = r.chain[r.chain.length - 1];\n const connect = last.cardinality === 'one' ? one : many;\n const args = r.chain.map((c) => {\n const dest = tableDefs.get(c.destSchema);\n if (!dest) throw new Error(`@orbit/orm-core: relationship \"${tableName}.${r.name}\" references unknown table \"${c.destSchema}\"`);\n return { sourceField: [...c.sourceField], destField: [...c.destField], destSchema: dest };\n });\n // `one`/`many` accept 1 (direct) or 2 (junction) hops.\n out[r.name] = (connect as (...a: unknown[]) => unknown)(...args);\n }\n return out as never;\n }),\n );\n }\n\n return createSchema({ tables: tables as never, relationships: rels as never });\n}\n","// Codegen: turn a {@link SchemaIR} into Orbit-schema TypeScript *source*. Unlike\n// the runtime builder, this preserves each column's custom `$type<>()` and enum\n// types (emitted as `string<...>()` / `json<...>()`), so the generated schema is\n// fully typed. Output is plain text; the CLI optionally runs Prettier over it.\n\nimport type { IRColumn, IRRelationship, IRTable, SchemaIR } from './ir.ts';\n\nexport interface EmitOptions {\n /** Module the Orbit schema helpers are imported from. Default `@orbit/client`. */\n readonly importFrom?: string;\n /** Append `.js` to the import (Node16/NodeNext ESM). Default false. */\n readonly jsExtension?: boolean;\n /** Exported schema const name. Default `schema`. */\n readonly schemaName?: string;\n /** Also emit `export type <Table> = RowOf<typeof <table>>` for each table. Default true. */\n readonly rowTypes?: boolean;\n /** Header comment lines (without leading `//`). */\n readonly header?: readonly string[];\n /**\n * Extra `import type { ... } from '...'` lines to prepend — used to bring in the\n * named TypeScript types referenced by resolved custom column types (e.g. a\n * `jsonb().$type<PostMeta>()` resolves to `PostMeta`, imported from the schema).\n */\n readonly typeImports?: readonly { readonly module: string; readonly names: readonly string[] }[];\n}\n\nconst RESERVED = new Set([\n 'break', 'case', 'catch', 'class', 'const', 'continue', 'debugger', 'default', 'delete', 'do', 'else',\n 'export', 'extends', 'false', 'finally', 'for', 'function', 'if', 'import', 'in', 'instanceof', 'new',\n 'null', 'return', 'super', 'switch', 'this', 'throw', 'true', 'try', 'typeof', 'var', 'void', 'while',\n 'with', 'yield', 'let', 'static', 'enum', 'await', 'implements', 'package', 'protected', 'interface',\n 'private', 'public', 'schema', 'table', 'string', 'number', 'boolean', 'json', 'optional', 'createSchema',\n 'relationships', 'RowOf', 'one', 'many',\n]);\n\nconst IDENT_RE = /^[A-Za-z_$][A-Za-z0-9_$]*$/;\n\nfunction isValidIdent(s: string): boolean {\n return IDENT_RE.test(s);\n}\n\n/** A stable, collision-free identifier for each table name (used as the const). */\nfunction tableIdentifiers(tables: readonly IRTable[]): Map<string, string> {\n const out = new Map<string, string>();\n const used = new Set<string>();\n for (const t of tables) {\n let base = t.name.replace(/[^A-Za-z0-9_$]/g, '_');\n if (!IDENT_RE.test(base) || base.startsWith('_') === false && /^[0-9]/.test(base)) base = `t_${base}`;\n if (RESERVED.has(base)) base = `${base}_`;\n let ident = base;\n let i = 2;\n while (used.has(ident)) ident = `${base}${i++}`;\n used.add(ident);\n out.set(t.name, ident);\n }\n return out;\n}\n\nfunction pascal(name: string): string {\n return name\n .split(/[^A-Za-z0-9]+/)\n .filter(Boolean)\n .map((p) => p.charAt(0).toUpperCase() + p.slice(1))\n .join('') || 'Row';\n}\n\nfunction keyLiteral(name: string): string {\n return isValidIdent(name) && !RESERVED.has(name) ? name : JSON.stringify(name);\n}\n\nfunction fieldArray(fields: readonly string[]): string {\n return `[${fields.map((f) => JSON.stringify(f)).join(', ')}]`;\n}\n\nfunction columnExpr(c: IRColumn): string {\n const generic = c.customType ? `<${c.customType}>` : '';\n const call = `${c.type}${generic}()`;\n return c.optional ? `optional(${call})` : call;\n}\n\nfunction emitTable(t: IRTable, ident: string): string {\n const cols = t.columns.map((c) => ` ${keyLiteral(c.name)}: ${columnExpr(c)},`).join('\\n');\n const pk = (t.primaryKey.length ? t.primaryKey : ['id']).map((k) => JSON.stringify(k)).join(', ');\n return `const ${ident} = table(${JSON.stringify(t.name)})\\n .columns({\\n${cols}\\n })\\n .primaryKey(${pk});`;\n}\n\nfunction emitRelationshipsBlock(\n tableName: string,\n rels: readonly IRRelationship[],\n idents: Map<string, string>,\n): string {\n const srcIdent = idents.get(tableName)!;\n const entries = rels\n .map((r) => {\n const last = r.chain[r.chain.length - 1];\n const fn = last.cardinality === 'one' ? 'one' : 'many';\n const hops = r.chain.map((c) => {\n const destIdent = idents.get(c.destSchema);\n if (!destIdent) throw new Error(`@orbit/orm-core: relationship \"${tableName}.${r.name}\" references unknown table \"${c.destSchema}\"`);\n return `{ sourceField: ${fieldArray(c.sourceField)}, destField: ${fieldArray(c.destField)}, destSchema: ${destIdent} }`;\n });\n const body = hops.length === 1 ? `${fn}(${hops[0]})` : `${fn}(\\n ${hops.join(',\\n ')},\\n )`;\n return ` ${keyLiteral(r.name)}: ${body},`;\n })\n .join('\\n');\n return ` relationships(${srcIdent}, ({ one, many }) => ({\\n${entries}\\n })),`;\n}\n\n/** Emit the full Orbit-schema TypeScript source for an IR. */\nexport function emitSchema(ir: SchemaIR, options: EmitOptions = {}): string {\n const {\n importFrom = '@zeronsh/orbit/client',\n jsExtension = false,\n schemaName = 'schema',\n rowTypes = true,\n header = ['Generated by @orbit/orm-core — do not edit by hand.'],\n } = options;\n\n const idents = tableIdentifiers(ir.tables);\n\n // Which helpers do we actually use?\n const used = new Set<string>(['createSchema', 'table']);\n for (const t of ir.tables) {\n for (const c of t.columns) {\n used.add(c.type);\n if (c.optional) used.add('optional');\n }\n }\n const hasRels = ir.relationships.length > 0;\n if (hasRels) used.add('relationships');\n if (rowTypes) used.add('RowOf');\n\n // `RowOf` is a type-only export; keep it in a separate `import type` for clarity.\n const valueImports = [...used].filter((u) => u !== 'RowOf');\n const order = ['createSchema', 'relationships', 'table', 'string', 'number', 'boolean', 'json', 'optional'];\n valueImports.sort((a, b) => {\n const ia = order.indexOf(a);\n const ib = order.indexOf(b);\n return (ia < 0 ? 99 : ia) - (ib < 0 ? 99 : ib);\n });\n\n const spec = jsExtension ? `${importFrom}` : importFrom; // import path unchanged; subpath rarely needs .js\n const lines: string[] = [];\n\n for (const h of header) lines.push(`// ${h}`);\n if (header.length) lines.push('');\n\n lines.push(`import {`);\n for (const v of valueImports) lines.push(` ${v},`);\n lines.push(`} from ${JSON.stringify(spec)};`);\n if (rowTypes) lines.push(`import type { RowOf } from ${JSON.stringify(spec)};`);\n for (const imp of options.typeImports ?? []) {\n if (imp.names.length) lines.push(`import type { ${[...imp.names].join(', ')} } from ${JSON.stringify(imp.module)};`);\n }\n lines.push('');\n\n // Tables.\n for (const t of ir.tables) {\n lines.push(emitTable(t, idents.get(t.name)!));\n lines.push('');\n }\n\n // Schema.\n const tableList = ir.tables.map((t) => idents.get(t.name)!).join(', ');\n lines.push(`export const ${schemaName} = createSchema({`);\n lines.push(` tables: [${tableList}],`);\n if (hasRels) {\n const byTable = new Map<string, IRRelationship[]>();\n for (const r of ir.relationships) {\n const l = byTable.get(r.table) ?? [];\n l.push(r);\n byTable.set(r.table, l);\n }\n lines.push(` relationships: [`);\n for (const t of ir.tables) {\n const list = byTable.get(t.name);\n if (list && list.length) lines.push(emitRelationshipsBlock(t.name, list, idents));\n }\n lines.push(` ],`);\n }\n lines.push(`});`);\n lines.push('');\n lines.push(`export type ${pascal(schemaName)} = typeof ${schemaName};`);\n\n // Row types.\n if (rowTypes) {\n lines.push('');\n const seen = new Set<string>([pascal(schemaName)]);\n for (const t of ir.tables) {\n let name = pascal(t.name);\n while (seen.has(name)) name = `${name}Row`;\n seen.add(name);\n lines.push(`export type ${name} = RowOf<typeof ${idents.get(t.name)!}>;`);\n }\n }\n\n return lines.join('\\n') + '\\n';\n}\n"]}
|
|
@@ -411,6 +411,12 @@ var Store = class {
|
|
|
411
411
|
#dirtyPending = /* @__PURE__ */ new Set();
|
|
412
412
|
#cleared = false;
|
|
413
413
|
#flushTimer;
|
|
414
|
+
/** Last server cookie (poke watermark). Persisted **after** the rows it covers
|
|
415
|
+
* (see `flush`) so a reload never restores a cookie ahead of the cached rows —
|
|
416
|
+
* which would make the server's delta-resume suppress rows the client never
|
|
417
|
+
* durably received (permanent divergence). */
|
|
418
|
+
#cookie;
|
|
419
|
+
#cookieDirty = false;
|
|
414
420
|
/** Effective-row keys touched since the last notify (delivered to listeners). */
|
|
415
421
|
#changed = [];
|
|
416
422
|
constructor(pkByTable = {}) {
|
|
@@ -515,6 +521,20 @@ var Store = class {
|
|
|
515
521
|
pendingMutations() {
|
|
516
522
|
return this.#pending.map((p) => p.mutation).filter((m) => m !== void 0);
|
|
517
523
|
}
|
|
524
|
+
/** Drop a single pending mutation by id — e.g. an undeliverable "poison" mutation
|
|
525
|
+
* the server keeps rejecting (oversized frame). Removes its optimistic overlay and,
|
|
526
|
+
* on the next flush, its persisted `p/` entry, so it is neither replayed on reconnect
|
|
527
|
+
* nor restored on reload. Returns whether such a mutation was present. */
|
|
528
|
+
dropPending(id) {
|
|
529
|
+
const idx = this.#pending.findIndex((p2) => p2.id === id);
|
|
530
|
+
if (idx === -1) return false;
|
|
531
|
+
const [p] = this.#pending.splice(idx, 1);
|
|
532
|
+
this.#dirtyPending.add(p.id);
|
|
533
|
+
for (const op of p.ops) this.#touch(op.tableName, this.#key(op.tableName, op.value));
|
|
534
|
+
this.#scheduleFlush();
|
|
535
|
+
this.#notify();
|
|
536
|
+
return true;
|
|
537
|
+
}
|
|
518
538
|
/** All rows for `table` with the optimistic overlay applied. */
|
|
519
539
|
effectiveRows(table2) {
|
|
520
540
|
const merged = new Map(this.#table(table2));
|
|
@@ -533,6 +553,18 @@ var Store = class {
|
|
|
533
553
|
this.#listeners.add(fn);
|
|
534
554
|
return () => this.#listeners.delete(fn);
|
|
535
555
|
}
|
|
556
|
+
/** Record the server cookie for the rows applied so far. It is persisted only in
|
|
557
|
+
* `flush`, **after** the row writes — so the durable cookie is never ahead of the
|
|
558
|
+
* durable rows. */
|
|
559
|
+
setCookie(cookie) {
|
|
560
|
+
this.#cookie = cookie;
|
|
561
|
+
this.#cookieDirty = true;
|
|
562
|
+
this.#scheduleFlush();
|
|
563
|
+
}
|
|
564
|
+
/** The last persisted/applied cookie (for resume `baseCookie`). */
|
|
565
|
+
cookie() {
|
|
566
|
+
return this.#cookie;
|
|
567
|
+
}
|
|
536
568
|
#notify() {
|
|
537
569
|
const changed = this.#changed;
|
|
538
570
|
this.#changed = [];
|
|
@@ -561,6 +593,8 @@ var Store = class {
|
|
|
561
593
|
this.#pending.push(p);
|
|
562
594
|
for (const op of p.ops) loaded.push({ table: op.tableName, key: this.#key(op.tableName, op.value) });
|
|
563
595
|
}
|
|
596
|
+
const cookie = await kv.get("cookie");
|
|
597
|
+
if (typeof cookie === "string") this.#cookie = cookie;
|
|
564
598
|
this.#changed.push(...loaded);
|
|
565
599
|
this.#notify();
|
|
566
600
|
}
|
|
@@ -594,6 +628,10 @@ var Store = class {
|
|
|
594
628
|
}
|
|
595
629
|
this.#dirtyPending.clear();
|
|
596
630
|
await Promise.all(ps);
|
|
631
|
+
if (this.#cookieDirty && this.#cookie !== void 0) {
|
|
632
|
+
await kv.set("cookie", this.#cookie);
|
|
633
|
+
this.#cookieDirty = false;
|
|
634
|
+
}
|
|
597
635
|
}
|
|
598
636
|
};
|
|
599
637
|
|
|
@@ -614,6 +652,22 @@ function typeRank(v) {
|
|
|
614
652
|
return 4;
|
|
615
653
|
}
|
|
616
654
|
}
|
|
655
|
+
function compareStringsUtf8(a, b) {
|
|
656
|
+
if (a === b) return 0;
|
|
657
|
+
const ia = a[Symbol.iterator]();
|
|
658
|
+
const ib = b[Symbol.iterator]();
|
|
659
|
+
for (; ; ) {
|
|
660
|
+
const na = ia.next();
|
|
661
|
+
const nb = ib.next();
|
|
662
|
+
if (na.done) return nb.done ? 0 : -1;
|
|
663
|
+
if (nb.done) return 1;
|
|
664
|
+
if (na.value !== nb.value) {
|
|
665
|
+
const ca = na.value.codePointAt(0);
|
|
666
|
+
const cb = nb.value.codePointAt(0);
|
|
667
|
+
if (ca !== cb) return ca < cb ? -1 : 1;
|
|
668
|
+
}
|
|
669
|
+
}
|
|
670
|
+
}
|
|
617
671
|
function compareValues(a, b) {
|
|
618
672
|
if (isNull(a) && isNull(b)) return 0;
|
|
619
673
|
if (isNull(a)) return -1;
|
|
@@ -621,7 +675,7 @@ function compareValues(a, b) {
|
|
|
621
675
|
if (typeof a === typeof b) {
|
|
622
676
|
if (typeof a === "number") return a < b ? -1 : a > b ? 1 : 0;
|
|
623
677
|
if (typeof a === "boolean") return a === b ? 0 : a ? 1 : -1;
|
|
624
|
-
if (typeof a === "string") return a
|
|
678
|
+
if (typeof a === "string") return compareStringsUtf8(a, b);
|
|
625
679
|
return 0;
|
|
626
680
|
}
|
|
627
681
|
return typeRank(a) - typeRank(b);
|
|
@@ -1812,8 +1866,7 @@ var Orbit = class {
|
|
|
1812
1866
|
if (typeof savedNextID === "number" && savedNextID > this.#nextMutationID) {
|
|
1813
1867
|
this.#nextMutationID = savedNextID;
|
|
1814
1868
|
}
|
|
1815
|
-
|
|
1816
|
-
if (typeof c === "string") this.#cookie = c;
|
|
1869
|
+
this.#cookie = this.#store.cookie();
|
|
1817
1870
|
} catch {
|
|
1818
1871
|
}
|
|
1819
1872
|
}
|
|
@@ -1851,10 +1904,29 @@ var Orbit = class {
|
|
|
1851
1904
|
ws.addEventListener("message", (ev) => {
|
|
1852
1905
|
this.#onMessage(JSON.parse(ev.data));
|
|
1853
1906
|
});
|
|
1854
|
-
ws.addEventListener("close", () => {
|
|
1907
|
+
ws.addEventListener("close", (ev) => {
|
|
1855
1908
|
this.#connecting = false;
|
|
1856
1909
|
if (this.#ws === ws) this.#ws = void 0;
|
|
1857
1910
|
this.#poke = null;
|
|
1911
|
+
if (ev.code === 1009 && this.#unconfirmedPushes.size > 0) {
|
|
1912
|
+
let poisonId;
|
|
1913
|
+
let maxSize = -1;
|
|
1914
|
+
for (const [id, msg] of this.#unconfirmedPushes) {
|
|
1915
|
+
const size = JSON.stringify(msg).length;
|
|
1916
|
+
if (size > maxSize) {
|
|
1917
|
+
maxSize = size;
|
|
1918
|
+
poisonId = id;
|
|
1919
|
+
}
|
|
1920
|
+
}
|
|
1921
|
+
if (poisonId !== void 0) {
|
|
1922
|
+
this.#unconfirmedPushes.delete(poisonId);
|
|
1923
|
+
this.#store.dropPending(poisonId);
|
|
1924
|
+
this.#onError?.({
|
|
1925
|
+
kind: "mutation-too-large",
|
|
1926
|
+
message: `dropped mutation ${poisonId} (~${maxSize} bytes): server closed with code 1009 (message too big)`
|
|
1927
|
+
});
|
|
1928
|
+
}
|
|
1929
|
+
}
|
|
1858
1930
|
this.#scheduleReconnect();
|
|
1859
1931
|
});
|
|
1860
1932
|
ws.addEventListener("error", () => ws.close());
|
|
@@ -1903,7 +1975,7 @@ var Orbit = class {
|
|
|
1903
1975
|
this.#store.confirmThrough(confirmed);
|
|
1904
1976
|
}
|
|
1905
1977
|
this.#cookie = body.cookie;
|
|
1906
|
-
|
|
1978
|
+
this.#store.setCookie(body.cookie);
|
|
1907
1979
|
this.#reconnectMs = 500;
|
|
1908
1980
|
return;
|
|
1909
1981
|
}
|
|
@@ -1975,5 +2047,5 @@ var IDBKV = class {
|
|
|
1975
2047
|
};
|
|
1976
2048
|
|
|
1977
2049
|
export { IDBKV, MaterializedView, MemoryKV, MemorySource, MemorySourceProvider, Orbit, PROTOCOL_VERSION, Query, QueryManager, SchemaQuery, SourceConnection, Store, StoreProvider, TypedQuery, View, boolean, buildPipeline, buildSchemaQueries, collectOps, compareValues, createBuilder, createOrbitApi, createSchema, defineMutation, defineQuery, evaluate, hashAST, hashString, json, nodeToRow, number, optional, parseTTL, relationships, string, table, tablesOf, unwrapSingular, validateArgs, valuesEqual };
|
|
1978
|
-
//# sourceMappingURL=chunk-
|
|
1979
|
-
//# sourceMappingURL=chunk-
|
|
2050
|
+
//# sourceMappingURL=chunk-LUFJQUF4.js.map
|
|
2051
|
+
//# sourceMappingURL=chunk-LUFJQUF4.js.map
|