@proofkit/fmodata 0.1.0-alpha.10 → 0.1.0-alpha.11
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/README.md +32 -22
- package/dist/esm/client/base-table.d.ts +8 -5
- package/dist/esm/client/base-table.js.map +1 -1
- package/dist/esm/client/build-occurrences.d.ts +74 -0
- package/dist/esm/client/build-occurrences.js +31 -0
- package/dist/esm/client/build-occurrences.js.map +1 -0
- package/dist/esm/client/entity-set.d.ts +2 -2
- package/dist/esm/client/entity-set.js +12 -1
- package/dist/esm/client/entity-set.js.map +1 -1
- package/dist/esm/client/query-builder.d.ts +2 -2
- package/dist/esm/client/query-builder.js +13 -2
- package/dist/esm/client/query-builder.js.map +1 -1
- package/dist/esm/client/record-builder.d.ts +1 -2
- package/dist/esm/client/record-builder.js.map +1 -1
- package/dist/esm/client/table-occurrence.d.ts +26 -12
- package/dist/esm/client/table-occurrence.js +14 -30
- package/dist/esm/client/table-occurrence.js.map +1 -1
- package/dist/esm/index.d.ts +5 -2
- package/dist/esm/index.js +4 -5
- package/dist/esm/index.js.map +1 -1
- package/package.json +1 -1
- package/src/client/base-table.ts +8 -5
- package/src/client/build-occurrences.ts +155 -0
- package/src/client/entity-set.ts +20 -5
- package/src/client/query-builder.ts +17 -8
- package/src/client/record-builder.ts +1 -4
- package/src/client/table-occurrence.ts +50 -69
- package/src/index.ts +8 -8
package/README.md
CHANGED
|
@@ -127,13 +127,9 @@ const connection = new FMServerConnection({
|
|
|
127
127
|
|
|
128
128
|
### Schema Definitions
|
|
129
129
|
|
|
130
|
-
This library relies on a schema-first approach for good type-safety and optional runtime validation. These are abstracted into BaseTable and TableOccurrence
|
|
130
|
+
This library relies on a schema-first approach for good type-safety and optional runtime validation. These are abstracted into BaseTable and TableOccurrence types to match FileMaker concepts.
|
|
131
131
|
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
- **`defineBaseTable()`** and **`defineTableOccurrence()`** - Recommended for better type inference, especially when using entity IDs (FMFID/FMTID). These functions provide improved TypeScript type inference for field names in queries.
|
|
135
|
-
|
|
136
|
-
- **`new BaseTable()`** and **`new TableOccurrence()`** - Still supported for backward compatibility, but may have slightly less precise type inference in some cases.
|
|
132
|
+
Use **`defineBaseTable()`** and **`defineTableOccurrence()`** to create your schemas. These functions provide full TypeScript type inference for field names in queries.
|
|
137
133
|
|
|
138
134
|
A `BaseTable` defines the schema for your FileMaker table using Standard Schema. These examples show zod, but you can use any other validation library that supports Standard Schema.
|
|
139
135
|
|
|
@@ -155,9 +151,7 @@ const contactsBase = defineBaseTable({
|
|
|
155
151
|
});
|
|
156
152
|
```
|
|
157
153
|
|
|
158
|
-
A `TableOccurrence` is the actual entry point for the OData service on the FileMaker server. It
|
|
159
|
-
|
|
160
|
-
**Recommended:** Use `defineTableOccurrence()` for better type inference. You can also use `new TableOccurrence()` directly.
|
|
154
|
+
A `TableOccurrence` is the actual entry point for the OData service on the FileMaker server. It allows you to reference the same base table multiple times with different names.
|
|
161
155
|
|
|
162
156
|
```typescript
|
|
163
157
|
import { defineTableOccurrence } from "@proofkit/fmodata";
|
|
@@ -640,9 +634,15 @@ const result = await db
|
|
|
640
634
|
|
|
641
635
|
### Defining Navigation
|
|
642
636
|
|
|
643
|
-
|
|
637
|
+
Use `buildOccurrences()` to define relationships between tables. This function takes an array of table occurrences and a configuration object that specifies navigation relationships using type-safe string references:
|
|
644
638
|
|
|
645
639
|
```typescript
|
|
640
|
+
import {
|
|
641
|
+
defineBaseTable,
|
|
642
|
+
defineTableOccurrence,
|
|
643
|
+
buildOccurrences,
|
|
644
|
+
} from "@proofkit/fmodata";
|
|
645
|
+
|
|
646
646
|
const contactsBase = defineBaseTable({
|
|
647
647
|
schema: {
|
|
648
648
|
id: z.string(),
|
|
@@ -661,8 +661,7 @@ const usersBase = defineBaseTable({
|
|
|
661
661
|
idField: "id",
|
|
662
662
|
});
|
|
663
663
|
|
|
664
|
-
//
|
|
665
|
-
// Create base occurrences first, then add navigation
|
|
664
|
+
// Step 1: Define base table occurrences (without navigation)
|
|
666
665
|
const _contactsTO = defineTableOccurrence({
|
|
667
666
|
name: "contacts",
|
|
668
667
|
baseTable: contactsBase,
|
|
@@ -673,21 +672,32 @@ const _usersTO = defineTableOccurrence({
|
|
|
673
672
|
baseTable: usersBase,
|
|
674
673
|
});
|
|
675
674
|
|
|
676
|
-
//
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
675
|
+
// Step 2: Build occurrences with navigation using string references
|
|
676
|
+
// The strings autocomplete to valid table occurrence names!
|
|
677
|
+
const occurrences = buildOccurrences({
|
|
678
|
+
occurrences: [_contactsTO, _usersTO],
|
|
679
|
+
navigation: {
|
|
680
|
+
contacts: ["users"],
|
|
681
|
+
users: ["contacts"],
|
|
682
|
+
},
|
|
683
683
|
});
|
|
684
684
|
|
|
685
|
-
//
|
|
686
|
-
const
|
|
687
|
-
|
|
685
|
+
// Use with your database
|
|
686
|
+
const db = connection.database("MyDB", {
|
|
687
|
+
occurrences: occurrences,
|
|
688
688
|
});
|
|
689
689
|
```
|
|
690
690
|
|
|
691
|
+
The `buildOccurrences` function accepts an object with:
|
|
692
|
+
|
|
693
|
+
- `occurrences` - Array of TableOccurrences to build
|
|
694
|
+
- `navigation` - Optional object mapping TO names to arrays of navigation targets
|
|
695
|
+
|
|
696
|
+
It returns a tuple in the same order as the input array, with full autocomplete for navigation target names. Self-navigation is prevented at the type level.
|
|
697
|
+
|
|
698
|
+
- Handles circular references automatically
|
|
699
|
+
- Returns fully typed `TableOccurrence` instances with resolved navigation
|
|
700
|
+
|
|
691
701
|
### Navigating Between Tables
|
|
692
702
|
|
|
693
703
|
Navigate to related records:
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { StandardSchemaV1 } from '@standard-schema/spec';
|
|
2
2
|
/**
|
|
3
3
|
* BaseTable defines the schema and configuration for a table.
|
|
4
|
+
* Use `defineBaseTable()` to create instances with proper type inference.
|
|
4
5
|
*
|
|
5
6
|
* @template Schema - Record of field names to StandardSchemaV1 validators
|
|
6
7
|
* @template IdField - The name of the primary key field (optional, automatically read-only)
|
|
@@ -10,8 +11,9 @@ import { StandardSchemaV1 } from '@standard-schema/spec';
|
|
|
10
11
|
* @example Basic table with auto-inferred required fields
|
|
11
12
|
* ```ts
|
|
12
13
|
* import { z } from "zod";
|
|
14
|
+
* import { defineBaseTable } from "@proofkit/fmodata";
|
|
13
15
|
*
|
|
14
|
-
* const usersTable =
|
|
16
|
+
* const usersTable = defineBaseTable({
|
|
15
17
|
* schema: {
|
|
16
18
|
* id: z.string(), // Auto-required (not nullable), auto-readOnly (idField)
|
|
17
19
|
* name: z.string(), // Auto-required (not nullable)
|
|
@@ -26,8 +28,9 @@ import { StandardSchemaV1 } from '@standard-schema/spec';
|
|
|
26
28
|
* @example Table with additional required and readOnly fields
|
|
27
29
|
* ```ts
|
|
28
30
|
* import { z } from "zod";
|
|
31
|
+
* import { defineBaseTable } from "@proofkit/fmodata";
|
|
29
32
|
*
|
|
30
|
-
* const usersTable =
|
|
33
|
+
* const usersTable = defineBaseTable({
|
|
31
34
|
* schema: {
|
|
32
35
|
* id: z.string(), // Auto-required, auto-readOnly (idField)
|
|
33
36
|
* createdAt: z.string(), // Read-only system field
|
|
@@ -46,8 +49,9 @@ import { StandardSchemaV1 } from '@standard-schema/spec';
|
|
|
46
49
|
* @example Table with multiple read-only fields
|
|
47
50
|
* ```ts
|
|
48
51
|
* import { z } from "zod";
|
|
52
|
+
* import { defineBaseTable } from "@proofkit/fmodata";
|
|
49
53
|
*
|
|
50
|
-
* const usersTable =
|
|
54
|
+
* const usersTable = defineBaseTable({
|
|
51
55
|
* schema: {
|
|
52
56
|
* id: z.string(),
|
|
53
57
|
* createdAt: z.string(),
|
|
@@ -94,8 +98,7 @@ export declare class BaseTable<Schema extends Record<string, StandardSchemaV1> =
|
|
|
94
98
|
/**
|
|
95
99
|
* Creates a BaseTable with proper TypeScript type inference.
|
|
96
100
|
*
|
|
97
|
-
*
|
|
98
|
-
* field names are properly typed throughout the library.
|
|
101
|
+
* Use this function to create BaseTable instances with full type safety.
|
|
99
102
|
*
|
|
100
103
|
* @example Without entity IDs
|
|
101
104
|
* ```ts
|
|
@@ -1 +1 @@
|
|
|
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 *\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 *\n * const usersTable =
|
|
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;"}
|
|
@@ -0,0 +1,74 @@
|
|
|
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 {};
|
|
@@ -0,0 +1,31 @@
|
|
|
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
|
|
@@ -0,0 +1 @@
|
|
|
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;"}
|
|
@@ -11,8 +11,7 @@ import { Database } from './database.js';
|
|
|
11
11
|
type ExtractNavigationNames<O extends TableOccurrence<any, any, any, any> | undefined> = O extends TableOccurrence<any, any, infer Nav, any> ? Nav extends Record<string, any> ? keyof Nav & string : never : never;
|
|
12
12
|
type ExtractSchemaFromOccurrence<O> = O extends TableOccurrence<infer BT, any, any, any> ? BT extends BaseTable<infer S, any, any, any> ? S : never : never;
|
|
13
13
|
type ExtractDefaultSelect<O> = O extends TableOccurrence<infer BT, any, any, infer DefSelect> ? BT extends BaseTable<infer S, any, any, any> ? DefSelect extends "all" ? keyof S : DefSelect extends "schema" ? keyof S : DefSelect extends readonly (infer K)[] ? K & keyof S : keyof S : never : never;
|
|
14
|
-
type
|
|
15
|
-
type FindNavigationTarget<O extends TableOccurrence<any, any, any, any> | undefined, Name extends string> = O extends TableOccurrence<any, any, infer Nav, any> ? Nav extends Record<string, any> ? Name extends keyof Nav ? ResolveNavigationItem<Nav[Name]> : TableOccurrence<BaseTable<Record<string, StandardSchemaV1>, any, any, any>, any, any, any> : TableOccurrence<BaseTable<Record<string, StandardSchemaV1>, any, any, any>, any, any, any> : TableOccurrence<BaseTable<Record<string, StandardSchemaV1>, any, any, any>, any, any, any>;
|
|
14
|
+
type FindNavigationTarget<O extends TableOccurrence<any, any, any, any> | undefined, Name extends string> = O extends TableOccurrence<any, any, infer Nav, any> ? Nav extends Record<string, any> ? Name extends keyof Nav ? Nav[Name] : TableOccurrence<BaseTable<Record<string, StandardSchemaV1>, any, any, any>, any, any, any> : TableOccurrence<BaseTable<Record<string, StandardSchemaV1>, any, any, any>, any, any, any> : TableOccurrence<BaseTable<Record<string, StandardSchemaV1>, any, any, any>, any, any, any>;
|
|
16
15
|
export declare class EntitySet<Schema extends Record<string, StandardSchemaV1> = any, Occ extends TableOccurrence<any, any, any, any> | undefined = undefined> {
|
|
17
16
|
private occurrence?;
|
|
18
17
|
private tableName;
|
|
@@ -22,6 +21,7 @@ export declare class EntitySet<Schema extends Record<string, StandardSchemaV1> =
|
|
|
22
21
|
private isNavigateFromEntitySet?;
|
|
23
22
|
private navigateRelation?;
|
|
24
23
|
private navigateSourceTableName?;
|
|
24
|
+
private navigateBasePath?;
|
|
25
25
|
constructor(config: {
|
|
26
26
|
occurrence?: Occ;
|
|
27
27
|
tableName: string;
|
|
@@ -7,6 +7,7 @@ import { InsertBuilder } from "./insert-builder.js";
|
|
|
7
7
|
import { DeleteBuilder } from "./delete-builder.js";
|
|
8
8
|
import { UpdateBuilder } from "./update-builder.js";
|
|
9
9
|
class EntitySet {
|
|
10
|
+
// Full base path for chained navigations
|
|
10
11
|
constructor(config) {
|
|
11
12
|
__publicField(this, "occurrence");
|
|
12
13
|
__publicField(this, "tableName");
|
|
@@ -17,6 +18,7 @@ class EntitySet {
|
|
|
17
18
|
__publicField(this, "isNavigateFromEntitySet");
|
|
18
19
|
__publicField(this, "navigateRelation");
|
|
19
20
|
__publicField(this, "navigateSourceTableName");
|
|
21
|
+
__publicField(this, "navigateBasePath");
|
|
20
22
|
this.occurrence = config.occurrence;
|
|
21
23
|
this.tableName = config.tableName;
|
|
22
24
|
this.databaseName = config.databaseName;
|
|
@@ -60,6 +62,7 @@ class EntitySet {
|
|
|
60
62
|
builder.isNavigate = true;
|
|
61
63
|
builder.navigateRelation = this.navigateRelation;
|
|
62
64
|
builder.navigateSourceTableName = this.navigateSourceTableName;
|
|
65
|
+
builder.navigateBasePath = this.navigateBasePath;
|
|
63
66
|
}
|
|
64
67
|
return builder.top(1e3);
|
|
65
68
|
}
|
|
@@ -130,7 +133,15 @@ class EntitySet {
|
|
|
130
133
|
});
|
|
131
134
|
entitySet.isNavigateFromEntitySet = true;
|
|
132
135
|
entitySet.navigateRelation = relationName;
|
|
133
|
-
|
|
136
|
+
if (this.isNavigateFromEntitySet && this.navigateBasePath) {
|
|
137
|
+
entitySet.navigateBasePath = `${this.navigateBasePath}/${this.navigateRelation}`;
|
|
138
|
+
entitySet.navigateSourceTableName = this.navigateSourceTableName;
|
|
139
|
+
} else if (this.isNavigateFromEntitySet && this.navigateRelation) {
|
|
140
|
+
entitySet.navigateBasePath = `${this.navigateSourceTableName}/${this.navigateRelation}`;
|
|
141
|
+
entitySet.navigateSourceTableName = this.navigateSourceTableName;
|
|
142
|
+
} else {
|
|
143
|
+
entitySet.navigateSourceTableName = this.tableName;
|
|
144
|
+
}
|
|
134
145
|
return entitySet;
|
|
135
146
|
}
|
|
136
147
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"entity-set.js","sources":["../../../src/client/entity-set.ts"],"sourcesContent":["import type {\n ExecutionContext,\n InferSchemaType,\n WithSystemFields,\n InsertData,\n UpdateData,\n} from \"../types\";\nimport type { StandardSchemaV1 } from \"@standard-schema/spec\";\nimport type { BaseTable } from \"./base-table\";\nimport type { TableOccurrence } from \"./table-occurrence\";\nimport { QueryBuilder } from \"./query-builder\";\nimport { RecordBuilder } from \"./record-builder\";\nimport { InsertBuilder } from \"./insert-builder\";\nimport { DeleteBuilder } from \"./delete-builder\";\nimport { UpdateBuilder } from \"./update-builder\";\nimport { Database } from \"./database\";\n\n// Helper type to extract navigation relation names from an occurrence\ntype ExtractNavigationNames<\n O extends TableOccurrence<any, any, any, any> | undefined,\n> =\n O extends TableOccurrence<any, any, infer Nav, any>\n ? Nav extends Record<string, any>\n ? keyof Nav & string\n : never\n : never;\n\n// Helper type to extract schema from a TableOccurrence\ntype ExtractSchemaFromOccurrence<O> =\n O extends TableOccurrence<infer BT, any, any, any>\n ? BT extends BaseTable<infer S, any, any, any>\n ? S\n : never\n : never;\n\n// Helper type to extract defaultSelect from a TableOccurrence\ntype ExtractDefaultSelect<O> =\n O extends TableOccurrence<infer BT, any, any, infer DefSelect>\n ? BT extends BaseTable<infer S, any, any, any>\n ? DefSelect extends \"all\"\n ? keyof S\n : DefSelect extends \"schema\"\n ? keyof S\n : DefSelect extends readonly (infer K)[]\n ? K & keyof S\n : keyof S\n : never\n : never;\n\n// Helper type to resolve a navigation item (handles both direct and lazy-loaded)\ntype ResolveNavigationItem<T> = T extends () => infer R ? R : T;\n\n// Helper type to find target occurrence by relation name\ntype FindNavigationTarget<\n O extends TableOccurrence<any, any, any, any> | undefined,\n Name extends string,\n> =\n O extends TableOccurrence<any, any, infer Nav, any>\n ? Nav extends Record<string, any>\n ? Name extends keyof Nav\n ? ResolveNavigationItem<Nav[Name]>\n : TableOccurrence<\n BaseTable<Record<string, StandardSchemaV1>, any, any, any>,\n any,\n any,\n any\n >\n : TableOccurrence<\n BaseTable<Record<string, StandardSchemaV1>, any, any, any>,\n any,\n any,\n any\n >\n : TableOccurrence<\n BaseTable<Record<string, StandardSchemaV1>, any, any, any>,\n any,\n any,\n any\n >;\n\n// Helper type to get the inferred schema type from a target occurrence\ntype GetTargetSchemaType<\n O extends TableOccurrence<any, any, any, any> | undefined,\n Rel extends string,\n> = [FindNavigationTarget<O, Rel>] extends [\n TableOccurrence<infer BT, any, any, any>,\n]\n ? [BT] extends [BaseTable<infer S, any, any, any>]\n ? [S] extends [Record<string, StandardSchemaV1>]\n ? InferSchemaType<S>\n : Record<string, any>\n : Record<string, any>\n : Record<string, any>;\n\nexport class EntitySet<\n Schema extends Record<string, StandardSchemaV1> = any,\n Occ extends TableOccurrence<any, any, any, any> | undefined = undefined,\n> {\n private occurrence?: Occ;\n private tableName: string;\n private databaseName: string;\n private context: ExecutionContext;\n private database: Database<any>; // Database instance for accessing occurrences\n private isNavigateFromEntitySet?: boolean;\n private navigateRelation?: string;\n private navigateSourceTableName?: string;\n\n constructor(config: {\n occurrence?: Occ;\n tableName: string;\n databaseName: string;\n context: ExecutionContext;\n database?: any;\n }) {\n this.occurrence = config.occurrence;\n this.tableName = config.tableName;\n this.databaseName = config.databaseName;\n this.context = config.context;\n this.database = config.database;\n }\n\n // Type-only method to help TypeScript infer the schema from occurrence\n static create<\n OccurrenceSchema extends Record<string, StandardSchemaV1>,\n Occ extends\n | TableOccurrence<\n BaseTable<OccurrenceSchema, any, any, any>,\n any,\n any,\n any\n >\n | undefined = undefined,\n >(config: {\n occurrence?: Occ;\n tableName: string;\n databaseName: string;\n context: ExecutionContext;\n database: Database<any>;\n }): EntitySet<OccurrenceSchema, Occ> {\n return new EntitySet<OccurrenceSchema, Occ>({\n occurrence: config.occurrence,\n tableName: config.tableName,\n databaseName: config.databaseName,\n context: config.context,\n database: config.database,\n });\n }\n\n list(): QueryBuilder<\n InferSchemaType<Schema>,\n Occ extends TableOccurrence<any, any, any, any>\n ? ExtractDefaultSelect<Occ>\n : keyof InferSchemaType<Schema>,\n false,\n false,\n Occ\n > {\n const builder = new QueryBuilder<\n InferSchemaType<Schema>,\n Occ extends TableOccurrence<any, any, any, any>\n ? ExtractDefaultSelect<Occ>\n : keyof InferSchemaType<Schema>,\n false,\n false,\n Occ\n >({\n occurrence: this.occurrence as Occ,\n tableName: this.tableName,\n databaseName: this.databaseName,\n context: this.context,\n databaseUseEntityIds: this.database?.isUsingEntityIds() ?? false,\n });\n\n // Apply defaultSelect if occurrence exists and select hasn't been called\n if (this.occurrence) {\n const defaultSelect = this.occurrence.defaultSelect;\n\n if (defaultSelect === \"schema\") {\n // Extract field names from schema\n const schema = this.occurrence.baseTable.schema;\n const fields = Object.keys(schema) as (keyof InferSchemaType<Schema>)[];\n // Deduplicate fields (same as select method)\n const uniqueFields = [...new Set(fields)];\n return builder.select(...uniqueFields).top(1000);\n } else if (Array.isArray(defaultSelect)) {\n // Use the provided field names, deduplicated\n const uniqueFields = [\n ...new Set(defaultSelect),\n ] as (keyof InferSchemaType<Schema>)[];\n return builder.select(...uniqueFields).top(1000);\n }\n // If defaultSelect is \"all\", no changes needed (current behavior)\n }\n\n // Propagate navigation context if present\n if (this.isNavigateFromEntitySet) {\n (builder as any).isNavigate = true;\n (builder as any).navigateRelation = this.navigateRelation;\n (builder as any).navigateSourceTableName = this.navigateSourceTableName;\n // navigateRecordId is intentionally not set (undefined) to indicate navigation from EntitySet\n }\n\n // Apply default pagination limit of 1000 records to prevent stack overflow\n // with large datasets. Users can override with .top() if needed.\n return builder.top(1000);\n }\n\n get(\n id: string | number,\n ): RecordBuilder<\n InferSchemaType<Schema>,\n false,\n keyof InferSchemaType<Schema>,\n Occ,\n keyof InferSchemaType<Schema>,\n {}\n > {\n const builder = new RecordBuilder<\n InferSchemaType<Schema>,\n false,\n keyof InferSchemaType<Schema>,\n Occ,\n keyof InferSchemaType<Schema>,\n {}\n >({\n occurrence: this.occurrence,\n tableName: this.tableName,\n databaseName: this.databaseName,\n context: this.context,\n recordId: id,\n databaseUseEntityIds: this.database?.isUsingEntityIds() ?? false,\n });\n // Propagate navigation context if present\n if (this.isNavigateFromEntitySet) {\n (builder as any).isNavigateFromEntitySet = true;\n (builder as any).navigateRelation = this.navigateRelation;\n (builder as any).navigateSourceTableName = this.navigateSourceTableName;\n }\n return builder;\n }\n\n // Overload: when returnFullRecord is explicitly false\n insert(\n data: Occ extends TableOccurrence<infer BT, any, any, any>\n ? BT extends BaseTable<any, any, any, any>\n ? InsertData<BT>\n : Partial<InferSchemaType<Schema>>\n : Partial<InferSchemaType<Schema>>,\n options: { returnFullRecord: false },\n ): InsertBuilder<InferSchemaType<Schema>, Occ, \"minimal\">;\n\n // Overload: when returnFullRecord is true or omitted (default)\n insert(\n data: Occ extends TableOccurrence<infer BT, any, any, any>\n ? BT extends BaseTable<any, any, any, any>\n ? InsertData<BT>\n : Partial<InferSchemaType<Schema>>\n : Partial<InferSchemaType<Schema>>,\n options?: { returnFullRecord?: true },\n ): InsertBuilder<InferSchemaType<Schema>, Occ, \"representation\">;\n\n // Implementation\n insert(\n data: Occ extends TableOccurrence<infer BT, any, any, any>\n ? BT extends BaseTable<any, any, any, any>\n ? InsertData<BT>\n : Partial<InferSchemaType<Schema>>\n : Partial<InferSchemaType<Schema>>,\n options?: { returnFullRecord?: boolean },\n ): InsertBuilder<InferSchemaType<Schema>, Occ, \"minimal\" | \"representation\"> {\n const returnPref =\n options?.returnFullRecord === false ? \"minimal\" : \"representation\";\n return new InsertBuilder<InferSchemaType<Schema>, Occ, typeof returnPref>({\n occurrence: this.occurrence,\n tableName: this.tableName,\n databaseName: this.databaseName,\n context: this.context,\n data: data as Partial<InferSchemaType<Schema>>,\n returnPreference: returnPref as any,\n databaseUseEntityIds: this.database?.isUsingEntityIds() ?? false,\n });\n }\n\n // Overload: when returnFullRecord is explicitly true\n update(\n data: Occ extends TableOccurrence<infer BT, any, any, any>\n ? BT extends BaseTable<any, any, any, any>\n ? UpdateData<BT>\n : Partial<InferSchemaType<Schema>>\n : Partial<InferSchemaType<Schema>>,\n options: { returnFullRecord: true },\n ): UpdateBuilder<\n InferSchemaType<Schema>,\n Occ extends TableOccurrence<infer BT, any, any, any>\n ? BT extends BaseTable<any, any, any, any>\n ? BT\n : BaseTable<Schema, any, any, any>\n : BaseTable<Schema, any, any, any>,\n \"representation\"\n >;\n\n // Overload: when returnFullRecord is false or omitted (default returns count)\n update(\n data: Occ extends TableOccurrence<infer BT, any, any, any>\n ? BT extends BaseTable<any, any, any, any>\n ? UpdateData<BT>\n : Partial<InferSchemaType<Schema>>\n : Partial<InferSchemaType<Schema>>,\n options?: { returnFullRecord?: false },\n ): UpdateBuilder<\n InferSchemaType<Schema>,\n Occ extends TableOccurrence<infer BT, any, any, any>\n ? BT extends BaseTable<any, any, any, any>\n ? BT\n : BaseTable<Schema, any, any, any>\n : BaseTable<Schema, any, any, any>,\n \"minimal\"\n >;\n\n // Implementation\n update(\n data: Occ extends TableOccurrence<infer BT, any, any, any>\n ? BT extends BaseTable<any, any, any, any>\n ? UpdateData<BT>\n : Partial<InferSchemaType<Schema>>\n : Partial<InferSchemaType<Schema>>,\n options?: { returnFullRecord?: boolean },\n ): UpdateBuilder<\n InferSchemaType<Schema>,\n Occ extends TableOccurrence<infer BT, any, any, any>\n ? BT extends BaseTable<any, any, any, any>\n ? BT\n : BaseTable<Schema, any, any, any>\n : BaseTable<Schema, any, any, any>,\n \"minimal\" | \"representation\"\n > {\n const returnPref =\n options?.returnFullRecord === true ? \"representation\" : \"minimal\";\n return new UpdateBuilder<\n InferSchemaType<Schema>,\n Occ extends TableOccurrence<infer BT, any, any, any>\n ? BT extends BaseTable<any, any, any, any>\n ? BT\n : BaseTable<Schema, any, any, any>\n : BaseTable<Schema, any, any, any>,\n typeof returnPref\n >({\n occurrence: this.occurrence,\n tableName: this.tableName,\n databaseName: this.databaseName,\n context: this.context,\n data: data as Partial<InferSchemaType<Schema>>,\n returnPreference: returnPref as any,\n databaseUseEntityIds: this.database?.isUsingEntityIds() ?? false,\n });\n }\n\n delete(): DeleteBuilder<InferSchemaType<Schema>> {\n return new DeleteBuilder<InferSchemaType<Schema>>({\n occurrence: this.occurrence,\n tableName: this.tableName,\n databaseName: this.databaseName,\n context: this.context,\n databaseUseEntityIds: this.database?.isUsingEntityIds() ?? false,\n });\n }\n\n // Overload for valid relation names - returns typed EntitySet\n navigate<RelationName extends ExtractNavigationNames<Occ>>(\n relationName: RelationName,\n ): EntitySet<\n ExtractSchemaFromOccurrence<\n FindNavigationTarget<Occ, RelationName>\n > extends Record<string, StandardSchemaV1>\n ? ExtractSchemaFromOccurrence<FindNavigationTarget<Occ, RelationName>>\n : Record<string, StandardSchemaV1>,\n FindNavigationTarget<Occ, RelationName>\n >;\n // Overload for arbitrary strings - returns generic EntitySet\n navigate(\n relationName: string,\n ): EntitySet<Record<string, StandardSchemaV1>, undefined>;\n // Implementation\n navigate(relationName: string): EntitySet<any, any> {\n // Use the target occurrence if available, otherwise allow untyped navigation\n // (useful when types might be incomplete)\n const targetOccurrence = this.occurrence?.navigation[relationName];\n const entitySet = new EntitySet<any, any>({\n occurrence: targetOccurrence,\n tableName: targetOccurrence?.name ?? relationName,\n databaseName: this.databaseName,\n context: this.context,\n });\n // Store the navigation info in the EntitySet\n // We'll need to pass this through when creating QueryBuilders\n (entitySet as any).isNavigateFromEntitySet = true;\n (entitySet as any).navigateRelation = relationName;\n (entitySet as any).navigateSourceTableName = this.tableName;\n return entitySet;\n }\n}\n"],"names":[],"mappings":"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"}
|
|
1
|
+
{"version":3,"file":"entity-set.js","sources":["../../../src/client/entity-set.ts"],"sourcesContent":["import type {\n ExecutionContext,\n InferSchemaType,\n WithSystemFields,\n InsertData,\n UpdateData,\n} from \"../types\";\nimport type { StandardSchemaV1 } from \"@standard-schema/spec\";\nimport type { BaseTable } from \"./base-table\";\nimport type { TableOccurrence } from \"./table-occurrence\";\nimport { QueryBuilder } from \"./query-builder\";\nimport { RecordBuilder } from \"./record-builder\";\nimport { InsertBuilder } from \"./insert-builder\";\nimport { DeleteBuilder } from \"./delete-builder\";\nimport { UpdateBuilder } from \"./update-builder\";\nimport { Database } from \"./database\";\n\n// Helper type to extract navigation relation names from an occurrence\ntype ExtractNavigationNames<\n O extends TableOccurrence<any, any, any, any> | undefined,\n> =\n O extends TableOccurrence<any, any, infer Nav, any>\n ? Nav extends Record<string, any>\n ? keyof Nav & string\n : never\n : never;\n\n// Helper type to extract schema from a TableOccurrence\ntype ExtractSchemaFromOccurrence<O> =\n O extends TableOccurrence<infer BT, any, any, any>\n ? BT extends BaseTable<infer S, any, any, any>\n ? S\n : never\n : never;\n\n// Helper type to extract defaultSelect from a TableOccurrence\ntype ExtractDefaultSelect<O> =\n O extends TableOccurrence<infer BT, any, any, infer DefSelect>\n ? BT extends BaseTable<infer S, any, any, any>\n ? DefSelect extends \"all\"\n ? keyof S\n : DefSelect extends \"schema\"\n ? keyof S\n : DefSelect extends readonly (infer K)[]\n ? K & keyof S\n : keyof S\n : never\n : never;\n\n// Helper type to find target occurrence by relation name\ntype FindNavigationTarget<\n O extends TableOccurrence<any, any, any, any> | undefined,\n Name extends string,\n> =\n O extends TableOccurrence<any, any, infer Nav, any>\n ? Nav extends Record<string, any>\n ? Name extends keyof Nav\n ? Nav[Name]\n : TableOccurrence<\n BaseTable<Record<string, StandardSchemaV1>, any, any, any>,\n any,\n any,\n any\n >\n : TableOccurrence<\n BaseTable<Record<string, StandardSchemaV1>, any, any, any>,\n any,\n any,\n any\n >\n : TableOccurrence<\n BaseTable<Record<string, StandardSchemaV1>, any, any, any>,\n any,\n any,\n any\n >;\n\n// Helper type to get the inferred schema type from a target occurrence\ntype GetTargetSchemaType<\n O extends TableOccurrence<any, any, any, any> | undefined,\n Rel extends string,\n> = [FindNavigationTarget<O, Rel>] extends [\n TableOccurrence<infer BT, any, any, any>,\n]\n ? [BT] extends [BaseTable<infer S, any, any, any>]\n ? [S] extends [Record<string, StandardSchemaV1>]\n ? InferSchemaType<S>\n : Record<string, any>\n : Record<string, any>\n : Record<string, any>;\n\nexport class EntitySet<\n Schema extends Record<string, StandardSchemaV1> = any,\n Occ extends TableOccurrence<any, any, any, any> | undefined = undefined,\n> {\n private occurrence?: Occ;\n private tableName: string;\n private databaseName: string;\n private context: ExecutionContext;\n private database: Database<any>; // Database instance for accessing occurrences\n private isNavigateFromEntitySet?: boolean;\n private navigateRelation?: string;\n private navigateSourceTableName?: string;\n private navigateBasePath?: string; // Full base path for chained navigations\n\n constructor(config: {\n occurrence?: Occ;\n tableName: string;\n databaseName: string;\n context: ExecutionContext;\n database?: any;\n }) {\n this.occurrence = config.occurrence;\n this.tableName = config.tableName;\n this.databaseName = config.databaseName;\n this.context = config.context;\n this.database = config.database;\n }\n\n // Type-only method to help TypeScript infer the schema from occurrence\n static create<\n OccurrenceSchema extends Record<string, StandardSchemaV1>,\n Occ extends\n | TableOccurrence<\n BaseTable<OccurrenceSchema, any, any, any>,\n any,\n any,\n any\n >\n | undefined = undefined,\n >(config: {\n occurrence?: Occ;\n tableName: string;\n databaseName: string;\n context: ExecutionContext;\n database: Database<any>;\n }): EntitySet<OccurrenceSchema, Occ> {\n return new EntitySet<OccurrenceSchema, Occ>({\n occurrence: config.occurrence,\n tableName: config.tableName,\n databaseName: config.databaseName,\n context: config.context,\n database: config.database,\n });\n }\n\n list(): QueryBuilder<\n InferSchemaType<Schema>,\n Occ extends TableOccurrence<any, any, any, any>\n ? ExtractDefaultSelect<Occ>\n : keyof InferSchemaType<Schema>,\n false,\n false,\n Occ\n > {\n const builder = new QueryBuilder<\n InferSchemaType<Schema>,\n Occ extends TableOccurrence<any, any, any, any>\n ? ExtractDefaultSelect<Occ>\n : keyof InferSchemaType<Schema>,\n false,\n false,\n Occ\n >({\n occurrence: this.occurrence as Occ,\n tableName: this.tableName,\n databaseName: this.databaseName,\n context: this.context,\n databaseUseEntityIds: this.database?.isUsingEntityIds() ?? false,\n });\n\n // Apply defaultSelect if occurrence exists and select hasn't been called\n if (this.occurrence) {\n const defaultSelect = this.occurrence.defaultSelect;\n\n if (defaultSelect === \"schema\") {\n // Extract field names from schema\n const schema = this.occurrence.baseTable.schema;\n const fields = Object.keys(schema) as (keyof InferSchemaType<Schema>)[];\n // Deduplicate fields (same as select method)\n const uniqueFields = [...new Set(fields)];\n return builder.select(...uniqueFields).top(1000);\n } else if (Array.isArray(defaultSelect)) {\n // Use the provided field names, deduplicated\n const uniqueFields = [\n ...new Set(defaultSelect),\n ] as (keyof InferSchemaType<Schema>)[];\n return builder.select(...uniqueFields).top(1000);\n }\n // If defaultSelect is \"all\", no changes needed (current behavior)\n }\n\n // Propagate navigation context if present\n if (this.isNavigateFromEntitySet) {\n (builder as any).isNavigate = true;\n (builder as any).navigateRelation = this.navigateRelation;\n (builder as any).navigateSourceTableName = this.navigateSourceTableName;\n (builder as any).navigateBasePath = this.navigateBasePath;\n // navigateRecordId is intentionally not set (undefined) to indicate navigation from EntitySet\n }\n\n // Apply default pagination limit of 1000 records to prevent stack overflow\n // with large datasets. Users can override with .top() if needed.\n return builder.top(1000);\n }\n\n get(\n id: string | number,\n ): RecordBuilder<\n InferSchemaType<Schema>,\n false,\n keyof InferSchemaType<Schema>,\n Occ,\n keyof InferSchemaType<Schema>,\n {}\n > {\n const builder = new RecordBuilder<\n InferSchemaType<Schema>,\n false,\n keyof InferSchemaType<Schema>,\n Occ,\n keyof InferSchemaType<Schema>,\n {}\n >({\n occurrence: this.occurrence,\n tableName: this.tableName,\n databaseName: this.databaseName,\n context: this.context,\n recordId: id,\n databaseUseEntityIds: this.database?.isUsingEntityIds() ?? false,\n });\n // Propagate navigation context if present\n if (this.isNavigateFromEntitySet) {\n (builder as any).isNavigateFromEntitySet = true;\n (builder as any).navigateRelation = this.navigateRelation;\n (builder as any).navigateSourceTableName = this.navigateSourceTableName;\n }\n return builder;\n }\n\n // Overload: when returnFullRecord is explicitly false\n insert(\n data: Occ extends TableOccurrence<infer BT, any, any, any>\n ? BT extends BaseTable<any, any, any, any>\n ? InsertData<BT>\n : Partial<InferSchemaType<Schema>>\n : Partial<InferSchemaType<Schema>>,\n options: { returnFullRecord: false },\n ): InsertBuilder<InferSchemaType<Schema>, Occ, \"minimal\">;\n\n // Overload: when returnFullRecord is true or omitted (default)\n insert(\n data: Occ extends TableOccurrence<infer BT, any, any, any>\n ? BT extends BaseTable<any, any, any, any>\n ? InsertData<BT>\n : Partial<InferSchemaType<Schema>>\n : Partial<InferSchemaType<Schema>>,\n options?: { returnFullRecord?: true },\n ): InsertBuilder<InferSchemaType<Schema>, Occ, \"representation\">;\n\n // Implementation\n insert(\n data: Occ extends TableOccurrence<infer BT, any, any, any>\n ? BT extends BaseTable<any, any, any, any>\n ? InsertData<BT>\n : Partial<InferSchemaType<Schema>>\n : Partial<InferSchemaType<Schema>>,\n options?: { returnFullRecord?: boolean },\n ): InsertBuilder<InferSchemaType<Schema>, Occ, \"minimal\" | \"representation\"> {\n const returnPref =\n options?.returnFullRecord === false ? \"minimal\" : \"representation\";\n return new InsertBuilder<InferSchemaType<Schema>, Occ, typeof returnPref>({\n occurrence: this.occurrence,\n tableName: this.tableName,\n databaseName: this.databaseName,\n context: this.context,\n data: data as Partial<InferSchemaType<Schema>>,\n returnPreference: returnPref as any,\n databaseUseEntityIds: this.database?.isUsingEntityIds() ?? false,\n });\n }\n\n // Overload: when returnFullRecord is explicitly true\n update(\n data: Occ extends TableOccurrence<infer BT, any, any, any>\n ? BT extends BaseTable<any, any, any, any>\n ? UpdateData<BT>\n : Partial<InferSchemaType<Schema>>\n : Partial<InferSchemaType<Schema>>,\n options: { returnFullRecord: true },\n ): UpdateBuilder<\n InferSchemaType<Schema>,\n Occ extends TableOccurrence<infer BT, any, any, any>\n ? BT extends BaseTable<any, any, any, any>\n ? BT\n : BaseTable<Schema, any, any, any>\n : BaseTable<Schema, any, any, any>,\n \"representation\"\n >;\n\n // Overload: when returnFullRecord is false or omitted (default returns count)\n update(\n data: Occ extends TableOccurrence<infer BT, any, any, any>\n ? BT extends BaseTable<any, any, any, any>\n ? UpdateData<BT>\n : Partial<InferSchemaType<Schema>>\n : Partial<InferSchemaType<Schema>>,\n options?: { returnFullRecord?: false },\n ): UpdateBuilder<\n InferSchemaType<Schema>,\n Occ extends TableOccurrence<infer BT, any, any, any>\n ? BT extends BaseTable<any, any, any, any>\n ? BT\n : BaseTable<Schema, any, any, any>\n : BaseTable<Schema, any, any, any>,\n \"minimal\"\n >;\n\n // Implementation\n update(\n data: Occ extends TableOccurrence<infer BT, any, any, any>\n ? BT extends BaseTable<any, any, any, any>\n ? UpdateData<BT>\n : Partial<InferSchemaType<Schema>>\n : Partial<InferSchemaType<Schema>>,\n options?: { returnFullRecord?: boolean },\n ): UpdateBuilder<\n InferSchemaType<Schema>,\n Occ extends TableOccurrence<infer BT, any, any, any>\n ? BT extends BaseTable<any, any, any, any>\n ? BT\n : BaseTable<Schema, any, any, any>\n : BaseTable<Schema, any, any, any>,\n \"minimal\" | \"representation\"\n > {\n const returnPref =\n options?.returnFullRecord === true ? \"representation\" : \"minimal\";\n return new UpdateBuilder<\n InferSchemaType<Schema>,\n Occ extends TableOccurrence<infer BT, any, any, any>\n ? BT extends BaseTable<any, any, any, any>\n ? BT\n : BaseTable<Schema, any, any, any>\n : BaseTable<Schema, any, any, any>,\n typeof returnPref\n >({\n occurrence: this.occurrence,\n tableName: this.tableName,\n databaseName: this.databaseName,\n context: this.context,\n data: data as Partial<InferSchemaType<Schema>>,\n returnPreference: returnPref as any,\n databaseUseEntityIds: this.database?.isUsingEntityIds() ?? false,\n });\n }\n\n delete(): DeleteBuilder<InferSchemaType<Schema>> {\n return new DeleteBuilder<InferSchemaType<Schema>>({\n occurrence: this.occurrence,\n tableName: this.tableName,\n databaseName: this.databaseName,\n context: this.context,\n databaseUseEntityIds: this.database?.isUsingEntityIds() ?? false,\n });\n }\n\n // Overload for valid relation names - returns typed EntitySet\n navigate<RelationName extends ExtractNavigationNames<Occ>>(\n relationName: RelationName,\n ): EntitySet<\n ExtractSchemaFromOccurrence<\n FindNavigationTarget<Occ, RelationName>\n > extends Record<string, StandardSchemaV1>\n ? ExtractSchemaFromOccurrence<FindNavigationTarget<Occ, RelationName>>\n : Record<string, StandardSchemaV1>,\n FindNavigationTarget<Occ, RelationName>\n >;\n // Overload for arbitrary strings - returns generic EntitySet\n navigate(\n relationName: string,\n ): EntitySet<Record<string, StandardSchemaV1>, undefined>;\n // Implementation\n navigate(relationName: string): EntitySet<any, any> {\n // Use the target occurrence if available, otherwise allow untyped navigation\n // (useful when types might be incomplete)\n const targetOccurrence = this.occurrence?.navigation[relationName];\n const entitySet = new EntitySet<any, any>({\n occurrence: targetOccurrence,\n tableName: targetOccurrence?.name ?? relationName,\n databaseName: this.databaseName,\n context: this.context,\n });\n // Store the navigation info in the EntitySet\n // We'll need to pass this through when creating QueryBuilders\n (entitySet as any).isNavigateFromEntitySet = true;\n (entitySet as any).navigateRelation = relationName;\n\n // Build the full base path for chained navigations\n // The base path should contain all segments BEFORE the final relation\n if (this.isNavigateFromEntitySet && this.navigateBasePath) {\n // Already have a base path from previous navigation - extend it with current relation\n (entitySet as any).navigateBasePath =\n `${this.navigateBasePath}/${this.navigateRelation}`;\n (entitySet as any).navigateSourceTableName = this.navigateSourceTableName;\n } else if (this.isNavigateFromEntitySet && this.navigateRelation) {\n // First chained navigation - create base path from source/relation\n (entitySet as any).navigateBasePath =\n `${this.navigateSourceTableName}/${this.navigateRelation}`;\n (entitySet as any).navigateSourceTableName = this.navigateSourceTableName;\n } else {\n // Initial navigation - source is just the table name\n (entitySet as any).navigateSourceTableName = this.tableName;\n }\n return entitySet;\n }\n}\n"],"names":[],"mappings":"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"}
|
|
@@ -6,8 +6,7 @@ import { BaseTable } from './base-table.js';
|
|
|
6
6
|
import { FFetchOptions } from '@fetchkit/ffetch';
|
|
7
7
|
import { StandardSchemaV1 } from '@standard-schema/spec';
|
|
8
8
|
type ExtractNavigationNames<O extends TableOccurrence<any, any, any, any> | undefined> = O extends TableOccurrence<any, any, infer Nav, any> ? Nav extends Record<string, any> ? keyof Nav & string : never : never;
|
|
9
|
-
type
|
|
10
|
-
type FindNavigationTarget<O extends TableOccurrence<any, any, any, any> | undefined, Name extends string> = O extends TableOccurrence<any, any, infer Nav, any> ? Nav extends Record<string, any> ? Name extends keyof Nav ? ResolveNavigationItem<Nav[Name]> : TableOccurrence<BaseTable<Record<string, StandardSchemaV1>, any, any, any>, any, any, any> : TableOccurrence<BaseTable<Record<string, StandardSchemaV1>, any, any, any>, any, any, any> : TableOccurrence<BaseTable<Record<string, StandardSchemaV1>, any, any, any>, any, any, any>;
|
|
9
|
+
type FindNavigationTarget<O extends TableOccurrence<any, any, any, any> | undefined, Name extends string> = O extends TableOccurrence<any, any, infer Nav, any> ? Nav extends Record<string, any> ? Name extends keyof Nav ? Nav[Name] : TableOccurrence<BaseTable<Record<string, StandardSchemaV1>, any, any, any>, any, any, any> : TableOccurrence<BaseTable<Record<string, StandardSchemaV1>, any, any, any>, any, any, any> : TableOccurrence<BaseTable<Record<string, StandardSchemaV1>, any, any, any>, any, any, any>;
|
|
11
10
|
type GetTargetSchemaType<O extends TableOccurrence<any, any, any, any> | undefined, Rel extends string> = [FindNavigationTarget<O, Rel>] extends [
|
|
12
11
|
TableOccurrence<infer BT, any, any, any>
|
|
13
12
|
] ? [BT] extends [BaseTable<infer S, any, any, any>] ? [S] extends [Record<string, StandardSchemaV1>] ? InferSchemaType<S> : Record<string, any> : Record<string, any> : Record<string, any>;
|
|
@@ -36,6 +35,7 @@ export declare class QueryBuilder<T extends Record<string, any>, Selected extend
|
|
|
36
35
|
private navigateRelation?;
|
|
37
36
|
private navigateSourceTableName?;
|
|
38
37
|
private navigateBaseRelation?;
|
|
38
|
+
private navigateBasePath?;
|
|
39
39
|
private databaseUseEntityIds;
|
|
40
40
|
constructor(config: {
|
|
41
41
|
occurrence?: Occ;
|
|
@@ -20,6 +20,8 @@ class QueryBuilder {
|
|
|
20
20
|
__publicField(this, "navigateRelation");
|
|
21
21
|
__publicField(this, "navigateSourceTableName");
|
|
22
22
|
__publicField(this, "navigateBaseRelation");
|
|
23
|
+
__publicField(this, "navigateBasePath");
|
|
24
|
+
// Full base path for chained entity set navigations
|
|
23
25
|
__publicField(this, "databaseUseEntityIds");
|
|
24
26
|
this.occurrence = config.occurrence;
|
|
25
27
|
this.tableName = config.tableName;
|
|
@@ -713,7 +715,12 @@ class QueryBuilder {
|
|
|
713
715
|
return queryParams ? `${path}${queryParams}` : path;
|
|
714
716
|
}
|
|
715
717
|
if (this.isNavigate && !this.navigateRecordId && this.navigateRelation && this.navigateSourceTableName) {
|
|
716
|
-
|
|
718
|
+
let path;
|
|
719
|
+
if (this.navigateBasePath) {
|
|
720
|
+
path = `/${this.navigateBasePath}/${this.navigateRelation}`;
|
|
721
|
+
} else {
|
|
722
|
+
path = `/${this.navigateSourceTableName}/${this.navigateRelation}`;
|
|
723
|
+
}
|
|
717
724
|
return queryParams ? `${path}${queryParams}` : path;
|
|
718
725
|
}
|
|
719
726
|
return `/${this.tableName}${queryParams}`;
|
|
@@ -742,7 +749,11 @@ class QueryBuilder {
|
|
|
742
749
|
url = `/${this.databaseName}/${this.navigateSourceTableName}('${this.navigateRecordId}')/${this.navigateRelation}${queryString}`;
|
|
743
750
|
}
|
|
744
751
|
} else if (this.isNavigate && !this.navigateRecordId && this.navigateRelation && this.navigateSourceTableName) {
|
|
745
|
-
|
|
752
|
+
if (this.navigateBasePath) {
|
|
753
|
+
url = `/${this.databaseName}/${this.navigateBasePath}/${this.navigateRelation}${queryString}`;
|
|
754
|
+
} else {
|
|
755
|
+
url = `/${this.databaseName}/${this.navigateSourceTableName}/${this.navigateRelation}${queryString}`;
|
|
756
|
+
}
|
|
746
757
|
} else if (this.isCountMode) {
|
|
747
758
|
url = `/${this.databaseName}/${this.tableName}/$count${queryString}`;
|
|
748
759
|
} else {
|