@proofkit/fmodata 0.1.0-alpha.13 → 0.1.0-alpha.15

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.
Files changed (143) hide show
  1. package/README.md +489 -334
  2. package/dist/esm/client/batch-builder.d.ts +7 -5
  3. package/dist/esm/client/batch-builder.js +84 -25
  4. package/dist/esm/client/batch-builder.js.map +1 -1
  5. package/dist/esm/client/builders/default-select.d.ts +7 -0
  6. package/dist/esm/client/builders/default-select.js +42 -0
  7. package/dist/esm/client/builders/default-select.js.map +1 -0
  8. package/dist/esm/client/builders/expand-builder.d.ts +43 -0
  9. package/dist/esm/client/builders/expand-builder.js +173 -0
  10. package/dist/esm/client/builders/expand-builder.js.map +1 -0
  11. package/dist/esm/client/builders/index.d.ts +8 -0
  12. package/dist/esm/client/builders/query-string-builder.d.ts +15 -0
  13. package/dist/esm/client/builders/query-string-builder.js +25 -0
  14. package/dist/esm/client/builders/query-string-builder.js.map +1 -0
  15. package/dist/esm/client/builders/response-processor.d.ts +39 -0
  16. package/dist/esm/client/builders/response-processor.js +170 -0
  17. package/dist/esm/client/builders/response-processor.js.map +1 -0
  18. package/dist/esm/client/builders/select-mixin.d.ts +31 -0
  19. package/dist/esm/client/builders/select-mixin.js +30 -0
  20. package/dist/esm/client/builders/select-mixin.js.map +1 -0
  21. package/dist/esm/client/builders/select-utils.d.ts +8 -0
  22. package/dist/esm/client/builders/select-utils.js +15 -0
  23. package/dist/esm/client/builders/select-utils.js.map +1 -0
  24. package/dist/esm/client/builders/shared-types.d.ts +39 -0
  25. package/dist/esm/client/builders/table-utils.d.ts +35 -0
  26. package/dist/esm/client/builders/table-utils.js +45 -0
  27. package/dist/esm/client/builders/table-utils.js.map +1 -0
  28. package/dist/esm/client/database.d.ts +3 -22
  29. package/dist/esm/client/database.js +14 -76
  30. package/dist/esm/client/database.js.map +1 -1
  31. package/dist/esm/client/delete-builder.d.ts +12 -19
  32. package/dist/esm/client/delete-builder.js +26 -26
  33. package/dist/esm/client/delete-builder.js.map +1 -1
  34. package/dist/esm/client/entity-set.d.ts +32 -32
  35. package/dist/esm/client/entity-set.js +92 -69
  36. package/dist/esm/client/entity-set.js.map +1 -1
  37. package/dist/esm/client/error-parser.d.ts +12 -0
  38. package/dist/esm/client/error-parser.js +30 -0
  39. package/dist/esm/client/error-parser.js.map +1 -0
  40. package/dist/esm/client/filemaker-odata.d.ts +2 -4
  41. package/dist/esm/client/filemaker-odata.js +1 -5
  42. package/dist/esm/client/filemaker-odata.js.map +1 -1
  43. package/dist/esm/client/insert-builder.d.ts +9 -12
  44. package/dist/esm/client/insert-builder.js +70 -24
  45. package/dist/esm/client/insert-builder.js.map +1 -1
  46. package/dist/esm/client/query/expand-builder.d.ts +35 -0
  47. package/dist/esm/client/query/index.d.ts +3 -0
  48. package/dist/esm/client/query/query-builder.d.ts +133 -0
  49. package/dist/esm/client/query/query-builder.js +505 -0
  50. package/dist/esm/client/query/query-builder.js.map +1 -0
  51. package/dist/esm/client/query/response-processor.d.ts +22 -0
  52. package/dist/esm/client/query/types.d.ts +52 -0
  53. package/dist/esm/client/query/url-builder.d.ts +71 -0
  54. package/dist/esm/client/query/url-builder.js +107 -0
  55. package/dist/esm/client/query/url-builder.js.map +1 -0
  56. package/dist/esm/client/query-builder.d.ts +1 -111
  57. package/dist/esm/client/record-builder.d.ts +56 -64
  58. package/dist/esm/client/record-builder.js +158 -297
  59. package/dist/esm/client/record-builder.js.map +1 -1
  60. package/dist/esm/client/response-processor.d.ts +3 -3
  61. package/dist/esm/client/update-builder.d.ts +17 -25
  62. package/dist/esm/client/update-builder.js +56 -30
  63. package/dist/esm/client/update-builder.js.map +1 -1
  64. package/dist/esm/errors.d.ts +8 -1
  65. package/dist/esm/errors.js +17 -0
  66. package/dist/esm/errors.js.map +1 -1
  67. package/dist/esm/index.d.ts +3 -7
  68. package/dist/esm/index.js +37 -8
  69. package/dist/esm/index.js.map +1 -1
  70. package/dist/esm/orm/column.d.ts +45 -0
  71. package/dist/esm/orm/column.js +59 -0
  72. package/dist/esm/orm/column.js.map +1 -0
  73. package/dist/esm/orm/field-builders.d.ts +154 -0
  74. package/dist/esm/orm/field-builders.js +152 -0
  75. package/dist/esm/orm/field-builders.js.map +1 -0
  76. package/dist/esm/orm/index.d.ts +4 -0
  77. package/dist/esm/orm/operators.d.ts +175 -0
  78. package/dist/esm/orm/operators.js +221 -0
  79. package/dist/esm/orm/operators.js.map +1 -0
  80. package/dist/esm/orm/table.d.ts +341 -0
  81. package/dist/esm/orm/table.js +211 -0
  82. package/dist/esm/orm/table.js.map +1 -0
  83. package/dist/esm/transform.d.ts +20 -21
  84. package/dist/esm/transform.js +34 -34
  85. package/dist/esm/transform.js.map +1 -1
  86. package/dist/esm/types.d.ts +73 -12
  87. package/dist/esm/types.js.map +1 -1
  88. package/dist/esm/validation.d.ts +14 -4
  89. package/dist/esm/validation.js +45 -1
  90. package/dist/esm/validation.js.map +1 -1
  91. package/package.json +22 -17
  92. package/src/client/batch-builder.ts +102 -33
  93. package/src/client/builders/default-select.ts +69 -0
  94. package/src/client/builders/expand-builder.ts +236 -0
  95. package/src/client/builders/index.ts +11 -0
  96. package/src/client/builders/query-string-builder.ts +41 -0
  97. package/src/client/builders/response-processor.ts +273 -0
  98. package/src/client/builders/select-mixin.ts +74 -0
  99. package/src/client/builders/select-utils.ts +34 -0
  100. package/src/client/builders/shared-types.ts +41 -0
  101. package/src/client/builders/table-utils.ts +87 -0
  102. package/src/client/database.ts +19 -160
  103. package/src/client/delete-builder.ts +48 -52
  104. package/src/client/entity-set.ts +227 -302
  105. package/src/client/error-parser.ts +59 -0
  106. package/src/client/filemaker-odata.ts +3 -14
  107. package/src/client/insert-builder.ts +126 -44
  108. package/src/client/query/expand-builder.ts +164 -0
  109. package/src/client/query/index.ts +13 -0
  110. package/src/client/query/query-builder.ts +826 -0
  111. package/src/client/query/response-processor.ts +244 -0
  112. package/src/client/query/types.ts +102 -0
  113. package/src/client/query/url-builder.ts +179 -0
  114. package/src/client/query-builder.ts +8 -1454
  115. package/src/client/record-builder.ts +336 -586
  116. package/src/client/response-processor.ts +4 -5
  117. package/src/client/update-builder.ts +113 -75
  118. package/src/errors.ts +22 -1
  119. package/src/index.ts +58 -5
  120. package/src/orm/column.ts +78 -0
  121. package/src/orm/field-builders.ts +296 -0
  122. package/src/orm/index.ts +60 -0
  123. package/src/orm/operators.ts +428 -0
  124. package/src/orm/table.ts +759 -0
  125. package/src/transform.ts +62 -48
  126. package/src/types.ts +88 -63
  127. package/src/validation.ts +76 -4
  128. package/LICENSE.md +0 -21
  129. package/dist/esm/client/base-table.d.ts +0 -128
  130. package/dist/esm/client/base-table.js +0 -57
  131. package/dist/esm/client/base-table.js.map +0 -1
  132. package/dist/esm/client/build-occurrences.d.ts +0 -74
  133. package/dist/esm/client/build-occurrences.js +0 -31
  134. package/dist/esm/client/build-occurrences.js.map +0 -1
  135. package/dist/esm/client/query-builder.js +0 -900
  136. package/dist/esm/client/query-builder.js.map +0 -1
  137. package/dist/esm/client/table-occurrence.d.ts +0 -86
  138. package/dist/esm/client/table-occurrence.js +0 -58
  139. package/dist/esm/client/table-occurrence.js.map +0 -1
  140. package/src/client/base-table.ts +0 -178
  141. package/src/client/build-occurrences.ts +0 -155
  142. package/src/client/query-builder.ts.bak +0 -1457
  143. package/src/client/table-occurrence.ts +0 -156
@@ -1,128 +0,0 @@
1
- import { StandardSchemaV1 } from '@standard-schema/spec';
2
- /**
3
- * BaseTable defines the schema and configuration for a table.
4
- * Use `defineBaseTable()` to create instances with proper type inference.
5
- *
6
- * @template Schema - Record of field names to StandardSchemaV1 validators
7
- * @template IdField - The name of the primary key field (optional, automatically read-only)
8
- * @template Required - Additional field names to require on insert (beyond auto-inferred required fields)
9
- * @template ReadOnly - Field names that cannot be modified via insert/update (idField is automatically read-only)
10
- *
11
- * @example Basic table with auto-inferred required fields
12
- * ```ts
13
- * import { z } from "zod";
14
- * import { defineBaseTable } from "@proofkit/fmodata";
15
- *
16
- * const usersTable = defineBaseTable({
17
- * schema: {
18
- * id: z.string(), // Auto-required (not nullable), auto-readOnly (idField)
19
- * name: z.string(), // Auto-required (not nullable)
20
- * email: z.string().nullable(), // Optional (nullable)
21
- * },
22
- * idField: "id",
23
- * });
24
- * // On insert: name is required, email is optional (id is excluded - readOnly)
25
- * // On update: name and email available (id is excluded - readOnly)
26
- * ```
27
- *
28
- * @example Table with additional required and readOnly fields
29
- * ```ts
30
- * import { z } from "zod";
31
- * import { defineBaseTable } from "@proofkit/fmodata";
32
- *
33
- * const usersTable = defineBaseTable({
34
- * schema: {
35
- * id: z.string(), // Auto-required, auto-readOnly (idField)
36
- * createdAt: z.string(), // Read-only system field
37
- * name: z.string(), // Auto-required
38
- * email: z.string().nullable(), // Optional by default...
39
- * legacyField: z.string().nullable(), // Optional by default...
40
- * },
41
- * idField: "id",
42
- * required: ["legacyField"], // Make legacyField required for new inserts
43
- * readOnly: ["createdAt"], // Exclude from insert/update
44
- * });
45
- * // On insert: name and legacyField required; email optional (id and createdAt excluded)
46
- * // On update: all fields optional (id and createdAt excluded)
47
- * ```
48
- *
49
- * @example Table with multiple read-only fields
50
- * ```ts
51
- * import { z } from "zod";
52
- * import { defineBaseTable } from "@proofkit/fmodata";
53
- *
54
- * const usersTable = defineBaseTable({
55
- * schema: {
56
- * id: z.string(),
57
- * createdAt: z.string(),
58
- * modifiedAt: z.string(),
59
- * createdBy: z.string(),
60
- * notes: z.string().nullable(),
61
- * },
62
- * idField: "id",
63
- * readOnly: ["createdAt", "modifiedAt", "createdBy"],
64
- * });
65
- * // On insert/update: only notes is available (id and system fields excluded)
66
- * ```
67
- */
68
- export declare class BaseTable<Schema extends Record<string, StandardSchemaV1> = any, IdField extends keyof Schema | undefined = undefined, Required extends readonly (keyof Schema | (string & {}))[] = readonly [], ReadOnly extends readonly (keyof Schema | (string & {}))[] = readonly []> {
69
- readonly schema: Schema;
70
- readonly idField?: IdField;
71
- readonly required?: Required;
72
- readonly readOnly?: ReadOnly;
73
- readonly fmfIds?: Record<keyof Schema | (string & {}), `FMFID:${string}`>;
74
- constructor(config: {
75
- schema: Schema;
76
- idField?: IdField;
77
- required?: Required;
78
- readOnly?: ReadOnly;
79
- fmfIds?: Record<string, `FMFID:${string}`>;
80
- });
81
- /**
82
- * Returns the FileMaker field ID (FMFID) for a given field name, or the field name itself if not using IDs.
83
- * @param fieldName - The field name to get the ID for
84
- * @returns The FMFID string or the original field name
85
- */
86
- getFieldId(fieldName: keyof Schema): string;
87
- /**
88
- * Returns the field name for a given FileMaker field ID (FMFID), or the ID itself if not found.
89
- * @param fieldId - The FMFID to get the field name for
90
- * @returns The field name or the original ID
91
- */
92
- getFieldName(fieldId: string): string;
93
- /**
94
- * Returns true if this BaseTable is using FileMaker field IDs.
95
- */
96
- isUsingFieldIds(): boolean;
97
- }
98
- /**
99
- * Creates a BaseTable with proper TypeScript type inference.
100
- *
101
- * Use this function to create BaseTable instances with full type safety.
102
- *
103
- * @example Without entity IDs
104
- * ```ts
105
- * const users = defineBaseTable({
106
- * schema: { id: z.string(), name: z.string() },
107
- * idField: "id",
108
- * });
109
- * ```
110
- *
111
- * @example With entity IDs (FileMaker field IDs)
112
- * ```ts
113
- * const products = defineBaseTable({
114
- * schema: { id: z.string(), name: z.string() },
115
- * idField: "id",
116
- * fmfIds: { id: "FMFID:1", name: "FMFID:2" },
117
- * });
118
- * ```
119
- */
120
- export declare function defineBaseTable<const Schema extends Record<string, StandardSchemaV1>, IdField extends keyof Schema | undefined = undefined, const Required extends readonly (keyof Schema | (string & {}))[] = readonly [], const ReadOnly extends readonly (keyof Schema | (string & {}))[] = readonly []>(config: {
121
- schema: Schema;
122
- idField?: IdField;
123
- required?: Required;
124
- readOnly?: ReadOnly;
125
- fmfIds?: {
126
- [K in keyof Schema | (string & {})]: `FMFID:${string}`;
127
- };
128
- }): BaseTable<Schema, IdField, Required, ReadOnly>;
@@ -1,57 +0,0 @@
1
- var __defProp = Object.defineProperty;
2
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
3
- var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
4
- class BaseTable {
5
- constructor(config) {
6
- __publicField(this, "schema");
7
- __publicField(this, "idField");
8
- __publicField(this, "required");
9
- __publicField(this, "readOnly");
10
- __publicField(this, "fmfIds");
11
- this.schema = config.schema;
12
- this.idField = config.idField;
13
- this.required = config.required;
14
- this.readOnly = config.readOnly;
15
- this.fmfIds = config.fmfIds;
16
- }
17
- /**
18
- * Returns the FileMaker field ID (FMFID) for a given field name, or the field name itself if not using IDs.
19
- * @param fieldName - The field name to get the ID for
20
- * @returns The FMFID string or the original field name
21
- */
22
- getFieldId(fieldName) {
23
- if (this.fmfIds && fieldName in this.fmfIds) {
24
- return this.fmfIds[fieldName];
25
- }
26
- return String(fieldName);
27
- }
28
- /**
29
- * Returns the field name for a given FileMaker field ID (FMFID), or the ID itself if not found.
30
- * @param fieldId - The FMFID to get the field name for
31
- * @returns The field name or the original ID
32
- */
33
- getFieldName(fieldId) {
34
- if (this.fmfIds) {
35
- for (const [fieldName, fmfId] of Object.entries(this.fmfIds)) {
36
- if (fmfId === fieldId) {
37
- return fieldName;
38
- }
39
- }
40
- }
41
- return fieldId;
42
- }
43
- /**
44
- * Returns true if this BaseTable is using FileMaker field IDs.
45
- */
46
- isUsingFieldIds() {
47
- return this.fmfIds !== void 0;
48
- }
49
- }
50
- function defineBaseTable(config) {
51
- return new BaseTable(config);
52
- }
53
- export {
54
- BaseTable,
55
- defineBaseTable
56
- };
57
- //# sourceMappingURL=base-table.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"base-table.js","sources":["../../../src/client/base-table.ts"],"sourcesContent":["import { StandardSchemaV1 } from \"@standard-schema/spec\";\n\n/**\n * BaseTable defines the schema and configuration for a table.\n * Use `defineBaseTable()` to create instances with proper type inference.\n *\n * @template Schema - Record of field names to StandardSchemaV1 validators\n * @template IdField - The name of the primary key field (optional, automatically read-only)\n * @template Required - Additional field names to require on insert (beyond auto-inferred required fields)\n * @template ReadOnly - Field names that cannot be modified via insert/update (idField is automatically read-only)\n *\n * @example Basic table with auto-inferred required fields\n * ```ts\n * import { z } from \"zod\";\n * import { defineBaseTable } from \"@proofkit/fmodata\";\n *\n * const usersTable = defineBaseTable({\n * schema: {\n * id: z.string(), // Auto-required (not nullable), auto-readOnly (idField)\n * name: z.string(), // Auto-required (not nullable)\n * email: z.string().nullable(), // Optional (nullable)\n * },\n * idField: \"id\",\n * });\n * // On insert: name is required, email is optional (id is excluded - readOnly)\n * // On update: name and email available (id is excluded - readOnly)\n * ```\n *\n * @example Table with additional required and readOnly fields\n * ```ts\n * import { z } from \"zod\";\n * import { defineBaseTable } from \"@proofkit/fmodata\";\n *\n * const usersTable = defineBaseTable({\n * schema: {\n * id: z.string(), // Auto-required, auto-readOnly (idField)\n * createdAt: z.string(), // Read-only system field\n * name: z.string(), // Auto-required\n * email: z.string().nullable(), // Optional by default...\n * legacyField: z.string().nullable(), // Optional by default...\n * },\n * idField: \"id\",\n * required: [\"legacyField\"], // Make legacyField required for new inserts\n * readOnly: [\"createdAt\"], // Exclude from insert/update\n * });\n * // On insert: name and legacyField required; email optional (id and createdAt excluded)\n * // On update: all fields optional (id and createdAt excluded)\n * ```\n *\n * @example Table with multiple read-only fields\n * ```ts\n * import { z } from \"zod\";\n * import { defineBaseTable } from \"@proofkit/fmodata\";\n *\n * const usersTable = defineBaseTable({\n * schema: {\n * id: z.string(),\n * createdAt: z.string(),\n * modifiedAt: z.string(),\n * createdBy: z.string(),\n * notes: z.string().nullable(),\n * },\n * idField: \"id\",\n * readOnly: [\"createdAt\", \"modifiedAt\", \"createdBy\"],\n * });\n * // On insert/update: only notes is available (id and system fields excluded)\n * ```\n */\nexport class BaseTable<\n Schema extends Record<string, StandardSchemaV1> = any,\n IdField extends keyof Schema | undefined = undefined,\n Required extends readonly (keyof Schema | (string & {}))[] = readonly [],\n ReadOnly extends readonly (keyof Schema | (string & {}))[] = readonly [],\n> {\n public readonly schema: Schema;\n public readonly idField?: IdField;\n public readonly required?: Required;\n public readonly readOnly?: ReadOnly;\n public readonly fmfIds?: Record<\n keyof Schema | (string & {}),\n `FMFID:${string}`\n >;\n\n constructor(config: {\n schema: Schema;\n idField?: IdField;\n required?: Required;\n readOnly?: ReadOnly;\n fmfIds?: Record<string, `FMFID:${string}`>;\n }) {\n this.schema = config.schema;\n this.idField = config.idField;\n this.required = config.required;\n this.readOnly = config.readOnly;\n this.fmfIds = config.fmfIds as\n | Record<keyof Schema, `FMFID:${string}`>\n | undefined;\n }\n\n /**\n * Returns the FileMaker field ID (FMFID) for a given field name, or the field name itself if not using IDs.\n * @param fieldName - The field name to get the ID for\n * @returns The FMFID string or the original field name\n */\n getFieldId(fieldName: keyof Schema): string {\n if (this.fmfIds && fieldName in this.fmfIds) {\n return this.fmfIds[fieldName];\n }\n return String(fieldName);\n }\n\n /**\n * Returns the field name for a given FileMaker field ID (FMFID), or the ID itself if not found.\n * @param fieldId - The FMFID to get the field name for\n * @returns The field name or the original ID\n */\n getFieldName(fieldId: string): string {\n if (this.fmfIds) {\n // Search for the field name that corresponds to this FMFID\n for (const [fieldName, fmfId] of Object.entries(this.fmfIds)) {\n if (fmfId === fieldId) {\n return fieldName;\n }\n }\n }\n return fieldId;\n }\n\n /**\n * Returns true if this BaseTable is using FileMaker field IDs.\n */\n isUsingFieldIds(): boolean {\n return this.fmfIds !== undefined;\n }\n}\n\n/**\n * Creates a BaseTable with proper TypeScript type inference.\n *\n * Use this function to create BaseTable instances with full type safety.\n *\n * @example Without entity IDs\n * ```ts\n * const users = defineBaseTable({\n * schema: { id: z.string(), name: z.string() },\n * idField: \"id\",\n * });\n * ```\n *\n * @example With entity IDs (FileMaker field IDs)\n * ```ts\n * const products = defineBaseTable({\n * schema: { id: z.string(), name: z.string() },\n * idField: \"id\",\n * fmfIds: { id: \"FMFID:1\", name: \"FMFID:2\" },\n * });\n * ```\n */\nexport function defineBaseTable<\n const Schema extends Record<string, StandardSchemaV1>,\n IdField extends keyof Schema | undefined = undefined,\n const Required extends readonly (\n | keyof Schema\n | (string & {})\n )[] = readonly [],\n const ReadOnly extends readonly (\n | keyof Schema\n | (string & {})\n )[] = readonly [],\n>(config: {\n schema: Schema;\n idField?: IdField;\n required?: Required;\n readOnly?: ReadOnly;\n fmfIds?: { [K in keyof Schema | (string & {})]: `FMFID:${string}` };\n}): BaseTable<Schema, IdField, Required, ReadOnly> {\n return new BaseTable(config);\n}\n"],"names":[],"mappings":";;;AAoEO,MAAM,UAKX;AAAA,EAUA,YAAY,QAMT;AAfa;AACA;AACA;AACA;AACA;AAYd,SAAK,SAAS,OAAO;AACrB,SAAK,UAAU,OAAO;AACtB,SAAK,WAAW,OAAO;AACvB,SAAK,WAAW,OAAO;AACvB,SAAK,SAAS,OAAO;AAAA,EAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAUvB,WAAW,WAAiC;AAC1C,QAAI,KAAK,UAAU,aAAa,KAAK,QAAQ;AACpC,aAAA,KAAK,OAAO,SAAS;AAAA,IAAA;AAE9B,WAAO,OAAO,SAAS;AAAA,EAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQzB,aAAa,SAAyB;AACpC,QAAI,KAAK,QAAQ;AAEJ,iBAAA,CAAC,WAAW,KAAK,KAAK,OAAO,QAAQ,KAAK,MAAM,GAAG;AAC5D,YAAI,UAAU,SAAS;AACd,iBAAA;AAAA,QAAA;AAAA,MACT;AAAA,IACF;AAEK,WAAA;AAAA,EAAA;AAAA;AAAA;AAAA;AAAA,EAMT,kBAA2B;AACzB,WAAO,KAAK,WAAW;AAAA,EAAA;AAE3B;AAwBO,SAAS,gBAWd,QAMiD;AAC1C,SAAA,IAAI,UAAU,MAAM;AAC7B;"}
@@ -1,74 +0,0 @@
1
- import { TableOccurrence } from './table-occurrence.js';
2
- /**
3
- * Extract the name type from a TableOccurrence
4
- */
5
- type ExtractName<TO> = TO extends TableOccurrence<any, infer Name, any, any> ? Name : never;
6
- /**
7
- * Extract all names from an array of TableOccurrences as a union
8
- */
9
- type ExtractNames<TOs extends readonly TableOccurrence<any, any, any, any>[]> = ExtractName<TOs[number]>;
10
- /**
11
- * Find a TableOccurrence by name from an array
12
- */
13
- type FindByName<TOs extends readonly TableOccurrence<any, any, any, any>[], Name extends string> = Extract<TOs[number], TableOccurrence<any, Name, any, any>>;
14
- /**
15
- * Navigation configuration - maps TO names to arrays of navigation target names.
16
- * A table occurrence cannot navigate to itself.
17
- */
18
- type NavigationConfig<TOs extends readonly TableOccurrence<any, any, any, any>[]> = {
19
- [K in ExtractNames<TOs>]?: Exclude<ExtractNames<TOs>, K>[];
20
- };
21
- /**
22
- * Resolve navigation config to actual TO record for a given TO name
23
- */
24
- type ResolveNavForTO<TOs extends readonly TableOccurrence<any, any, any, any>[], Nav extends NavigationConfig<TOs> | undefined, Name extends ExtractNames<TOs>> = Nav extends NavigationConfig<TOs> ? Nav[Name] extends infer NavNames extends string[] ? {
25
- [K in NavNames[number]]: FindByName<TOs, K>;
26
- } : {} : {};
27
- /**
28
- * Build the result type - a tuple of TOs with navigation resolved
29
- */
30
- type BuildResult<TOs extends readonly TableOccurrence<any, any, any, any>[], Nav extends NavigationConfig<TOs> | undefined> = {
31
- [K in keyof TOs]: TOs[K] extends TableOccurrence<infer BT, infer Name, any, infer DefSelect> ? Name extends ExtractNames<TOs> ? TableOccurrence<BT, Name, ResolveNavForTO<TOs, Nav, Name>, DefSelect> : TOs[K] : TOs[K];
32
- };
33
- /**
34
- * Builds TableOccurrences with navigation relationships resolved.
35
- *
36
- * This is the second phase of TO definition - after defining base TOs,
37
- * use this function to link them with navigation relationships.
38
- *
39
- * @example Full navigation
40
- * ```ts
41
- * const [contacts, users] = buildOccurrences({
42
- * occurrences: [_contacts, _users],
43
- * navigation: {
44
- * contacts: ["users"],
45
- * users: ["contacts"],
46
- * },
47
- * });
48
- * ```
49
- *
50
- * @example Partial navigation
51
- * ```ts
52
- * const [contacts, users] = buildOccurrences({
53
- * occurrences: [_contacts, _users],
54
- * navigation: {
55
- * contacts: ["users"],
56
- * },
57
- * });
58
- * ```
59
- *
60
- * @example No navigation
61
- * ```ts
62
- * const [contacts, users] = buildOccurrences({
63
- * occurrences: [_contacts, _users],
64
- * });
65
- * ```
66
- *
67
- * @param config - Configuration object with occurrences array and optional navigation
68
- * @returns Tuple of TableOccurrences with navigation resolved (same order as input)
69
- */
70
- export declare function buildOccurrences<const TOs extends readonly TableOccurrence<any, any, any, any>[], const Nav extends NavigationConfig<TOs> | undefined>(config: {
71
- occurrences: TOs;
72
- navigation?: Nav;
73
- }): BuildResult<TOs, Nav>;
74
- export {};
@@ -1,31 +0,0 @@
1
- import { TableOccurrence } from "./table-occurrence.js";
2
- function buildOccurrences(config) {
3
- const { occurrences, navigation } = config;
4
- const toByName = /* @__PURE__ */ new Map();
5
- for (const to of occurrences) {
6
- toByName.set(to.name, to);
7
- }
8
- const result = occurrences.map((to) => {
9
- const navNames = navigation == null ? void 0 : navigation[to.name];
10
- const resolvedNav = {};
11
- if (navNames) {
12
- for (const navName of navNames) {
13
- if (navName === to.name) {
14
- throw new Error(
15
- `TableOccurrence "${to.name}" cannot navigate to itself`
16
- );
17
- }
18
- const targetTO = toByName.get(navName);
19
- if (targetTO) {
20
- resolvedNav[navName] = targetTO;
21
- }
22
- }
23
- }
24
- return TableOccurrence._withNavigation(to, resolvedNav);
25
- });
26
- return result;
27
- }
28
- export {
29
- buildOccurrences
30
- };
31
- //# sourceMappingURL=build-occurrences.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"build-occurrences.js","sources":["../../../src/client/build-occurrences.ts"],"sourcesContent":["import { TableOccurrence } from \"./table-occurrence\";\n\n/**\n * Extract the name type from a TableOccurrence\n */\ntype ExtractName<TO> =\n TO extends TableOccurrence<any, infer Name, any, any> ? Name : never;\n\n/**\n * Extract all names from an array of TableOccurrences as a union\n */\ntype ExtractNames<TOs extends readonly TableOccurrence<any, any, any, any>[]> =\n ExtractName<TOs[number]>;\n\n/**\n * Find a TableOccurrence by name from an array\n */\ntype FindByName<\n TOs extends readonly TableOccurrence<any, any, any, any>[],\n Name extends string,\n> = Extract<TOs[number], TableOccurrence<any, Name, any, any>>;\n\n/**\n * Navigation configuration - maps TO names to arrays of navigation target names.\n * A table occurrence cannot navigate to itself.\n */\ntype NavigationConfig<\n TOs extends readonly TableOccurrence<any, any, any, any>[],\n> = {\n [K in ExtractNames<TOs>]?: Exclude<ExtractNames<TOs>, K>[];\n};\n\n/**\n * Resolve navigation config to actual TO record for a given TO name\n */\ntype ResolveNavForTO<\n TOs extends readonly TableOccurrence<any, any, any, any>[],\n Nav extends NavigationConfig<TOs> | undefined,\n Name extends ExtractNames<TOs>,\n> =\n Nav extends NavigationConfig<TOs>\n ? Nav[Name] extends infer NavNames extends string[]\n ? {\n [K in NavNames[number]]: FindByName<TOs, K>;\n }\n : {}\n : {};\n\n/**\n * Build the result type - a tuple of TOs with navigation resolved\n */\ntype BuildResult<\n TOs extends readonly TableOccurrence<any, any, any, any>[],\n Nav extends NavigationConfig<TOs> | undefined,\n> = {\n [K in keyof TOs]: TOs[K] extends TableOccurrence<\n infer BT,\n infer Name,\n any,\n infer DefSelect\n >\n ? Name extends ExtractNames<TOs>\n ? TableOccurrence<BT, Name, ResolveNavForTO<TOs, Nav, Name>, DefSelect>\n : TOs[K]\n : TOs[K];\n};\n\n/**\n * Configuration object for buildOccurrences\n */\ntype BuildOccurrencesConfig<\n TOs extends readonly TableOccurrence<any, any, any, any>[],\n> = {\n occurrences: TOs;\n navigation?: NavigationConfig<TOs>;\n};\n\n/**\n * Builds TableOccurrences with navigation relationships resolved.\n *\n * This is the second phase of TO definition - after defining base TOs,\n * use this function to link them with navigation relationships.\n *\n * @example Full navigation\n * ```ts\n * const [contacts, users] = buildOccurrences({\n * occurrences: [_contacts, _users],\n * navigation: {\n * contacts: [\"users\"],\n * users: [\"contacts\"],\n * },\n * });\n * ```\n *\n * @example Partial navigation\n * ```ts\n * const [contacts, users] = buildOccurrences({\n * occurrences: [_contacts, _users],\n * navigation: {\n * contacts: [\"users\"],\n * },\n * });\n * ```\n *\n * @example No navigation\n * ```ts\n * const [contacts, users] = buildOccurrences({\n * occurrences: [_contacts, _users],\n * });\n * ```\n *\n * @param config - Configuration object with occurrences array and optional navigation\n * @returns Tuple of TableOccurrences with navigation resolved (same order as input)\n */\nexport function buildOccurrences<\n const TOs extends readonly TableOccurrence<any, any, any, any>[],\n const Nav extends NavigationConfig<TOs> | undefined,\n>(config: { occurrences: TOs; navigation?: Nav }): BuildResult<TOs, Nav> {\n const { occurrences, navigation } = config;\n\n // Build a map of name -> TO for quick lookup\n const toByName = new Map<string, TableOccurrence<any, any, any, any>>();\n for (const to of occurrences) {\n toByName.set(to.name, to);\n }\n\n // Build result array with navigation resolved\n const result = occurrences.map((to) => {\n const navNames = navigation?.[to.name as keyof typeof navigation] as\n | string[]\n | undefined;\n\n // Resolve navigation names to actual TOs\n const resolvedNav: Record<string, TableOccurrence<any, any, any, any>> = {};\n if (navNames) {\n for (const navName of navNames) {\n // Prevent self-navigation\n if (navName === to.name) {\n throw new Error(\n `TableOccurrence \"${to.name}\" cannot navigate to itself`,\n );\n }\n const targetTO = toByName.get(navName);\n if (targetTO) {\n resolvedNav[navName] = targetTO;\n }\n }\n }\n\n // Create new TO with navigation using internal method\n return TableOccurrence._withNavigation(to, resolvedNav);\n });\n\n return result as BuildResult<TOs, Nav>;\n}\n"],"names":[],"mappings":";AAkHO,SAAS,iBAGd,QAAuE;AACjE,QAAA,EAAE,aAAa,WAAA,IAAe;AAG9B,QAAA,+BAAe,IAAiD;AACtE,aAAW,MAAM,aAAa;AACnB,aAAA,IAAI,GAAG,MAAM,EAAE;AAAA,EAAA;AAI1B,QAAM,SAAS,YAAY,IAAI,CAAC,OAAO;AAC/B,UAAA,WAAW,yCAAa,GAAG;AAKjC,UAAM,cAAmE,CAAC;AAC1E,QAAI,UAAU;AACZ,iBAAW,WAAW,UAAU;AAE1B,YAAA,YAAY,GAAG,MAAM;AACvB,gBAAM,IAAI;AAAA,YACR,oBAAoB,GAAG,IAAI;AAAA,UAC7B;AAAA,QAAA;AAEI,cAAA,WAAW,SAAS,IAAI,OAAO;AACrC,YAAI,UAAU;AACZ,sBAAY,OAAO,IAAI;AAAA,QAAA;AAAA,MACzB;AAAA,IACF;AAIK,WAAA,gBAAgB,gBAAgB,IAAI,WAAW;AAAA,EAAA,CACvD;AAEM,SAAA;AACT;"}