@pylo/node 0.0.11 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli.js +47 -65
- package/dist/codegen.d.ts +1 -0
- package/dist/index.d.ts +128 -43
- package/dist/index.js +199 -115
- package/dist/schema.d.ts +1 -0
- package/dist/schema.js +406 -0
- package/dist/shared-types-DqRv2JHW.d.ts +67 -0
- package/package.json +12 -5
package/dist/cli.js
CHANGED
|
@@ -34,7 +34,6 @@ async function loadConfig(cwd) {
|
|
|
34
34
|
}
|
|
35
35
|
return {
|
|
36
36
|
endpoint: DEFAULT_ENDPOINT,
|
|
37
|
-
unknownFieldBehavior: "error",
|
|
38
37
|
...config
|
|
39
38
|
};
|
|
40
39
|
}
|
|
@@ -124,18 +123,15 @@ query PyloSchemaFetch($pagination: PaginationInput) {
|
|
|
124
123
|
}
|
|
125
124
|
}
|
|
126
125
|
`;
|
|
127
|
-
async function
|
|
126
|
+
async function fetchSchemaWith(request) {
|
|
128
127
|
var _a, _b;
|
|
129
128
|
const allEntities = [];
|
|
130
129
|
let page = 1;
|
|
131
130
|
let hasMore = true;
|
|
132
131
|
while (hasMore) {
|
|
133
|
-
const response = await
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
{ pagination: { page, per_page: 50 } },
|
|
137
|
-
config.apiKey
|
|
138
|
-
);
|
|
132
|
+
const response = await request(ENTITY_LIST_QUERY, {
|
|
133
|
+
pagination: { page, per_page: 50 }
|
|
134
|
+
});
|
|
139
135
|
if (response.errors) {
|
|
140
136
|
const errMsg = Array.isArray(response.errors) ? response.errors.map((e) => e.message).join(", ") : (_b = (_a = response.errors.generalError) == null ? void 0 : _a.message) != null ? _b : "Unknown error";
|
|
141
137
|
throw new Error(`Failed to fetch schema: ${errMsg}`);
|
|
@@ -150,6 +146,11 @@ async function fetchSchema(config) {
|
|
|
150
146
|
}
|
|
151
147
|
return allEntities;
|
|
152
148
|
}
|
|
149
|
+
async function fetchSchema(config) {
|
|
150
|
+
return fetchSchemaWith(
|
|
151
|
+
(query, variables) => graphqlRequestWithApiKey(config.endpoint, query, variables, config.apiKey)
|
|
152
|
+
);
|
|
153
|
+
}
|
|
153
154
|
var DATA_TYPE_MAP = {
|
|
154
155
|
TEXT: "string",
|
|
155
156
|
LONGTEXT: "string",
|
|
@@ -263,6 +264,7 @@ function analyzeEntities(rawEntities) {
|
|
|
263
264
|
});
|
|
264
265
|
}
|
|
265
266
|
var VARIANT_TYPE = "{ variant: string; value: string }";
|
|
267
|
+
var REGISTERABLE_SOURCES = /* @__PURE__ */ new Set(["@pylo/node", "@pylo/nextjs"]);
|
|
266
268
|
function fieldTypeString(field) {
|
|
267
269
|
if (field.nullable) {
|
|
268
270
|
return `${field.tsType} | null`;
|
|
@@ -276,10 +278,21 @@ function indent(text, level) {
|
|
|
276
278
|
function getVariantFieldNames(entity) {
|
|
277
279
|
return entity.fields.filter((f) => f.variantFieldName !== null).map((f) => f.variantFieldName);
|
|
278
280
|
}
|
|
281
|
+
var NON_WRITABLE_FIELDS = /* @__PURE__ */ new Set(["integer_id", "created_at", "updated_at"]);
|
|
282
|
+
function generateReplaceVariablesField(entity) {
|
|
283
|
+
const fieldNames = entity.fields.map((f) => f.name).filter((name) => !NON_WRITABLE_FIELDS.has(name));
|
|
284
|
+
if (fieldNames.length === 0) return null;
|
|
285
|
+
const union = fieldNames.map((name) => `'${name}'`).join(" | ");
|
|
286
|
+
return [
|
|
287
|
+
"/**",
|
|
288
|
+
" * Field names whose template variables (e.g. `${replace_uuid.myNewEntity}`) the server",
|
|
289
|
+
" * should resolve to their concrete values during this upsert.",
|
|
290
|
+
" */",
|
|
291
|
+
`replace_variables?: Array<${union}>;`
|
|
292
|
+
].join("\n");
|
|
293
|
+
}
|
|
279
294
|
function generateEntityFieldsType(entity) {
|
|
280
|
-
const lines = entity.fields.map(
|
|
281
|
-
(f) => `${f.name}: ${fieldTypeString(f)};`
|
|
282
|
-
);
|
|
295
|
+
const lines = entity.fields.map((f) => `${f.name}: ${fieldTypeString(f)};`);
|
|
283
296
|
for (const variantName of getVariantFieldNames(entity)) {
|
|
284
297
|
lines.push(`${variantName}: ${VARIANT_TYPE}[] | null;`);
|
|
285
298
|
}
|
|
@@ -305,9 +318,7 @@ function generateCreateInputType(entity) {
|
|
|
305
318
|
for (const rel of entity.relations) {
|
|
306
319
|
for (const suffix of rel.suffixes) {
|
|
307
320
|
const valueType = rel.type === "hasMany" ? "Record<string, unknown>[]" : "Record<string, unknown>";
|
|
308
|
-
lines.push(
|
|
309
|
-
`${rel.fieldName}${suffix}?: ${valueType};`
|
|
310
|
-
);
|
|
321
|
+
lines.push(`${rel.fieldName}${suffix}?: ${valueType};`);
|
|
311
322
|
}
|
|
312
323
|
}
|
|
313
324
|
return lines.join("\n");
|
|
@@ -318,6 +329,10 @@ function generateUpdateInputType(entity) {
|
|
|
318
329
|
lines.push(
|
|
319
330
|
"__search_value?: { field: string; value?: string; not_found_behavior?: 'create' | 'ignore' | 'error'; search_in_all_field_variants?: boolean; multiple_results_allowed?: boolean; multiple_results_use_latest?: boolean };"
|
|
320
331
|
);
|
|
332
|
+
const replaceVariables = generateReplaceVariablesField(entity);
|
|
333
|
+
if (replaceVariables) {
|
|
334
|
+
lines.push(replaceVariables);
|
|
335
|
+
}
|
|
321
336
|
for (const field of entity.fields) {
|
|
322
337
|
if (field.name === "id" || field.name === "integer_id") continue;
|
|
323
338
|
if (field.name === "created_at" || field.name === "updated_at") continue;
|
|
@@ -329,9 +344,7 @@ function generateUpdateInputType(entity) {
|
|
|
329
344
|
for (const rel of entity.relations) {
|
|
330
345
|
for (const suffix of rel.suffixes) {
|
|
331
346
|
const valueType = rel.type === "hasMany" ? "Record<string, unknown>[]" : "Record<string, unknown>";
|
|
332
|
-
lines.push(
|
|
333
|
-
`${rel.fieldName}${suffix}?: ${valueType};`
|
|
334
|
-
);
|
|
347
|
+
lines.push(`${rel.fieldName}${suffix}?: ${valueType};`);
|
|
335
348
|
}
|
|
336
349
|
}
|
|
337
350
|
return lines.join("\n");
|
|
@@ -362,8 +375,6 @@ function generateIndexFile(entities, importSource) {
|
|
|
362
375
|
" SortInput,",
|
|
363
376
|
" SortOrder,",
|
|
364
377
|
" SearchValueInput,",
|
|
365
|
-
" SchemaMetadata,",
|
|
366
|
-
" EntityMetadata,",
|
|
367
378
|
`} from '${importSource}';`,
|
|
368
379
|
""
|
|
369
380
|
);
|
|
@@ -400,6 +411,16 @@ function generateIndexFile(entities, importSource) {
|
|
|
400
411
|
lines.push(" };");
|
|
401
412
|
}
|
|
402
413
|
lines.push("}", "");
|
|
414
|
+
if (REGISTERABLE_SOURCES.has(importSource)) {
|
|
415
|
+
lines.push(
|
|
416
|
+
`declare module '${importSource}' {`,
|
|
417
|
+
" interface PyloRegister {",
|
|
418
|
+
" schema: PyloSchema;",
|
|
419
|
+
" }",
|
|
420
|
+
"}",
|
|
421
|
+
""
|
|
422
|
+
);
|
|
423
|
+
}
|
|
403
424
|
return lines.join("\n");
|
|
404
425
|
}
|
|
405
426
|
function generateEntitiesFile(entities, importSource) {
|
|
@@ -425,57 +446,19 @@ function generateEntitiesFile(entities, importSource) {
|
|
|
425
446
|
}
|
|
426
447
|
for (const rel of entity.relations) {
|
|
427
448
|
if (rel.type === "hasOne") {
|
|
428
|
-
lines.push(
|
|
449
|
+
lines.push(
|
|
450
|
+
` ${rel.fieldName}?: { data: ${rel.targetEntityPascalName} } | null;`
|
|
451
|
+
);
|
|
429
452
|
} else {
|
|
430
|
-
lines.push(
|
|
453
|
+
lines.push(
|
|
454
|
+
` ${rel.fieldName}?: { data: ${rel.targetEntityPascalName}[]; pagination: PaginationData };`
|
|
455
|
+
);
|
|
431
456
|
}
|
|
432
457
|
}
|
|
433
458
|
lines.push("}", "");
|
|
434
459
|
}
|
|
435
460
|
return lines.join("\n");
|
|
436
461
|
}
|
|
437
|
-
function generateSchemaMetadataFile(entities, unknownFieldBehavior, importSource) {
|
|
438
|
-
const lines = [];
|
|
439
|
-
lines.push(
|
|
440
|
-
"// Auto-generated by @pylo/core codegen \u2014 DO NOT EDIT",
|
|
441
|
-
"",
|
|
442
|
-
`import type { SchemaMetadata } from '${importSource}';`,
|
|
443
|
-
"",
|
|
444
|
-
"export const schemaMetadata: SchemaMetadata = {",
|
|
445
|
-
` unknownFieldBehavior: '${unknownFieldBehavior}',`,
|
|
446
|
-
" entities: {"
|
|
447
|
-
);
|
|
448
|
-
for (const entity of entities) {
|
|
449
|
-
lines.push(` ${entity.key}: {`);
|
|
450
|
-
lines.push(` pascalName: '${entity.pascalName}',`);
|
|
451
|
-
const scalarNames = entity.fields.map((f) => `'${f.name}'`).join(", ");
|
|
452
|
-
lines.push(` scalarFieldNames: [${scalarNames}],`);
|
|
453
|
-
const variantNames = getVariantFieldNames(entity);
|
|
454
|
-
if (variantNames.length > 0) {
|
|
455
|
-
const variantNamesStr = variantNames.map((n) => `'${n}'`).join(", ");
|
|
456
|
-
lines.push(` variantFieldNames: [${variantNamesStr}],`);
|
|
457
|
-
}
|
|
458
|
-
const enumFields = entity.fields.filter((f) => f.enum !== null);
|
|
459
|
-
if (enumFields.length > 0) {
|
|
460
|
-
lines.push(" enumFields: {");
|
|
461
|
-
for (const f of enumFields) {
|
|
462
|
-
const vals = f.enum.values.map((v) => `'${v}'`).join(", ");
|
|
463
|
-
lines.push(` ${f.name}: [${vals}],`);
|
|
464
|
-
}
|
|
465
|
-
lines.push(" },");
|
|
466
|
-
}
|
|
467
|
-
lines.push(" relations: {");
|
|
468
|
-
for (const rel of entity.relations) {
|
|
469
|
-
lines.push(
|
|
470
|
-
` ${rel.fieldName}: { type: '${rel.type}', entity: '${rel.targetEntityKey}', pascalName: '${rel.targetEntityPascalName}' },`
|
|
471
|
-
);
|
|
472
|
-
}
|
|
473
|
-
lines.push(" },");
|
|
474
|
-
lines.push(" },");
|
|
475
|
-
}
|
|
476
|
-
lines.push(" },", "};", "");
|
|
477
|
-
return lines.join("\n");
|
|
478
|
-
}
|
|
479
462
|
function writeGeneratedFiles(outputDir, files) {
|
|
480
463
|
mkdirSync(outputDir, { recursive: true });
|
|
481
464
|
for (const [filename, content] of Object.entries(files)) {
|
|
@@ -499,8 +482,7 @@ async function generate(options) {
|
|
|
499
482
|
console.log("Generating types...");
|
|
500
483
|
const files = {
|
|
501
484
|
"index.ts": generateIndexFile(entities, importSource),
|
|
502
|
-
"entities.ts": generateEntitiesFile(entities, importSource)
|
|
503
|
-
"schema-metadata.ts": generateSchemaMetadataFile(entities, config.unknownFieldBehavior, importSource)
|
|
485
|
+
"entities.ts": generateEntitiesFile(entities, importSource)
|
|
504
486
|
};
|
|
505
487
|
console.log(`Writing files to ${outputDir}...`);
|
|
506
488
|
writeGeneratedFiles(outputDir, files);
|
package/dist/codegen.d.ts
CHANGED
package/dist/index.d.ts
CHANGED
|
@@ -47,21 +47,56 @@ interface PyloEvent {
|
|
|
47
47
|
ts: string;
|
|
48
48
|
properties: Record<string, unknown>;
|
|
49
49
|
}
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
50
|
+
type AggregateFunction = "count" | "sum" | "avg" | "min" | "max";
|
|
51
|
+
interface AggregateInput {
|
|
52
|
+
field: string;
|
|
53
|
+
function: AggregateFunction;
|
|
54
|
+
alias?: string;
|
|
55
|
+
}
|
|
56
|
+
interface TimeBucketInput {
|
|
57
|
+
field?: string;
|
|
58
|
+
interval: string;
|
|
59
|
+
timezone?: string;
|
|
60
|
+
}
|
|
61
|
+
interface DimensionInput {
|
|
62
|
+
field?: string;
|
|
63
|
+
timeBucket?: TimeBucketInput;
|
|
64
|
+
}
|
|
65
|
+
interface EventListFilterInput {
|
|
66
|
+
query?: QueryInput[];
|
|
67
|
+
sortby?: SortInput[];
|
|
68
|
+
aggregate?: AggregateInput[];
|
|
69
|
+
dimensions?: DimensionInput[];
|
|
70
|
+
limit?: number;
|
|
61
71
|
}
|
|
62
|
-
interface
|
|
63
|
-
|
|
64
|
-
|
|
72
|
+
interface EventListOptions {
|
|
73
|
+
filter?: EventListFilterInput;
|
|
74
|
+
pagination?: PaginationInput;
|
|
75
|
+
select_fields?: string[];
|
|
76
|
+
interval?: string;
|
|
77
|
+
timezone?: string;
|
|
78
|
+
group_by?: string[];
|
|
79
|
+
startTime?: string;
|
|
80
|
+
}
|
|
81
|
+
interface PyloEventListResult {
|
|
82
|
+
data: Array<Record<string, unknown>>;
|
|
83
|
+
pagination: PaginationData;
|
|
84
|
+
aggregations: Record<string, unknown> | null;
|
|
85
|
+
}
|
|
86
|
+
interface PyloEventProperty {
|
|
87
|
+
path: string;
|
|
88
|
+
type: string;
|
|
89
|
+
}
|
|
90
|
+
interface PyloEventFieldValue {
|
|
91
|
+
value: string;
|
|
92
|
+
count: number;
|
|
93
|
+
}
|
|
94
|
+
interface PyloEventPropertyKeysOptions {
|
|
95
|
+
filter?: FilterInput;
|
|
96
|
+
}
|
|
97
|
+
interface PyloEventFieldValuesOptions {
|
|
98
|
+
startTime?: string;
|
|
99
|
+
limit?: number;
|
|
65
100
|
}
|
|
66
101
|
|
|
67
102
|
type EntityName<S> = string & keyof S;
|
|
@@ -77,26 +112,26 @@ type UpsertInput<S, E extends EntityName<S>> = S[E] extends {
|
|
|
77
112
|
type OmitNever<T> = {
|
|
78
113
|
[K in keyof T as T[K] extends never ? never : K]: T[K];
|
|
79
114
|
};
|
|
80
|
-
type EntitySelect<S, E extends EntityName<S>, Depth extends number = 0> = Depth extends 5 ? Record<string,
|
|
115
|
+
type EntitySelect<S, E extends EntityName<S>, Depth extends number = 0> = Depth extends 5 ? Record<string, never> : OmitNever<{
|
|
81
116
|
[K in keyof EntityFields<S, E>]?: true;
|
|
82
117
|
}> & {
|
|
83
118
|
[K in keyof EntityRelations<S, E>]?: EntityRelations<S, E>[K] extends {
|
|
84
119
|
type: "hasOne";
|
|
85
120
|
entity: infer Target;
|
|
86
|
-
} ? Target extends EntityName<S> ?
|
|
87
|
-
select
|
|
121
|
+
} ? Target extends EntityName<S> ? {
|
|
122
|
+
select: EntitySelect<S, Target, Increment[Depth]>;
|
|
88
123
|
filter?: FilterInput;
|
|
89
|
-
} :
|
|
124
|
+
} : never : EntityRelations<S, E>[K] extends {
|
|
90
125
|
type: "hasMany";
|
|
91
126
|
entity: infer Target;
|
|
92
|
-
} ? Target extends EntityName<S> ?
|
|
93
|
-
select
|
|
127
|
+
} ? Target extends EntityName<S> ? {
|
|
128
|
+
select: EntitySelect<S, Target, Increment[Depth]>;
|
|
94
129
|
filter?: FilterInput;
|
|
95
130
|
pagination?: PaginationInput;
|
|
96
|
-
} :
|
|
131
|
+
} : never : never;
|
|
97
132
|
};
|
|
98
133
|
type Increment = [1, 2, 3, 4, 5, 5];
|
|
99
|
-
type EntityResult<S, E extends EntityName<S>, Select extends EntitySelect<S, E
|
|
134
|
+
type EntityResult<S, E extends EntityName<S>, Select extends EntitySelect<S, E>, Depth extends number = 0> = Depth extends 5 ? Record<string, unknown> : Select extends EntitySelect<S, E> ? OmitNever<ScalarResult<S, E, Select> & RelationResult<S, E, Select, Depth>> : EntityFields<S, E>;
|
|
100
135
|
type ScalarResult<S, E extends EntityName<S>, Select extends EntitySelect<S, E>> = {
|
|
101
136
|
[K in keyof Select & keyof EntityFields<S, E>]: Select[K] extends true ? EntityFields<S, E>[K] : never;
|
|
102
137
|
};
|
|
@@ -108,36 +143,29 @@ type RelationResult<S, E extends EntityName<S>, Select extends EntitySelect<S, E
|
|
|
108
143
|
select: infer SubSelect;
|
|
109
144
|
} ? SubSelect extends EntitySelect<S, Target> ? {
|
|
110
145
|
data: EntityResult<S, Target, SubSelect, Increment[Depth]>;
|
|
111
|
-
} | null : {
|
|
112
|
-
data: EntityFields<S, Target>;
|
|
113
|
-
} | null : Select[K] extends true ? {
|
|
114
|
-
data: EntityFields<S, Target>;
|
|
115
|
-
} | null : never : never : EntityRelations<S, E>[K] extends {
|
|
146
|
+
} | null : never : never : never : EntityRelations<S, E>[K] extends {
|
|
116
147
|
type: "hasMany";
|
|
117
148
|
entity: infer Target;
|
|
118
149
|
} ? Target extends EntityName<S> ? Select[K] extends {
|
|
119
150
|
select: infer SubSelect;
|
|
120
151
|
} ? SubSelect extends EntitySelect<S, Target> ? {
|
|
121
152
|
data: Array<EntityResult<S, Target, SubSelect, Increment[Depth]>>;
|
|
153
|
+
} & (Select[K] extends {
|
|
154
|
+
pagination: unknown;
|
|
155
|
+
} ? {
|
|
122
156
|
pagination: PaginationData;
|
|
123
|
-
} :
|
|
124
|
-
data: Array<EntityFields<S, Target>>;
|
|
125
|
-
pagination: PaginationData;
|
|
126
|
-
} : Select[K] extends true ? {
|
|
127
|
-
data: Array<EntityFields<S, Target>>;
|
|
128
|
-
pagination: PaginationData;
|
|
129
|
-
} : never : never : never;
|
|
157
|
+
} : unknown) : never : never : never : never;
|
|
130
158
|
};
|
|
131
159
|
type StrictSelect<Sel, Valid> = Valid & {
|
|
132
160
|
[K in keyof Sel]: K extends keyof Valid ? Sel[K] : never;
|
|
133
161
|
};
|
|
134
|
-
type ListOptions<S, E extends EntityName<S>, Sel extends EntitySelect<S, E
|
|
135
|
-
select
|
|
162
|
+
type ListOptions<S, E extends EntityName<S>, Sel extends EntitySelect<S, E>> = {
|
|
163
|
+
select: StrictSelect<Sel, EntitySelect<S, E>>;
|
|
136
164
|
filter?: FilterInput;
|
|
137
165
|
pagination?: PaginationInput;
|
|
138
166
|
};
|
|
139
|
-
type ByIdOptions<S, E extends EntityName<S>, Sel extends EntitySelect<S, E
|
|
140
|
-
select
|
|
167
|
+
type ByIdOptions<S, E extends EntityName<S>, Sel extends EntitySelect<S, E>> = {
|
|
168
|
+
select: StrictSelect<Sel, EntitySelect<S, E>>;
|
|
141
169
|
};
|
|
142
170
|
interface ListResult<T> {
|
|
143
171
|
data: T[];
|
|
@@ -160,13 +188,12 @@ type AuthProvider = () => Promise<{
|
|
|
160
188
|
}>;
|
|
161
189
|
interface ClientOptions {
|
|
162
190
|
endpoint?: string;
|
|
163
|
-
schemaMetadata: SchemaMetadata;
|
|
164
191
|
auth: AuthProvider;
|
|
165
192
|
headers?: Record<string, string>;
|
|
166
193
|
}
|
|
167
194
|
interface EntityClient<S, E extends EntityName<S>> {
|
|
168
|
-
list<Sel extends EntitySelect<S, E
|
|
169
|
-
byId<Sel extends EntitySelect<S, E
|
|
195
|
+
list<Sel extends EntitySelect<S, E>>(options: ListOptions<S, E, Sel> & RequestOptions): Promise<ListResult<EntityResult<S, E, Sel>>>;
|
|
196
|
+
byId<Sel extends EntitySelect<S, E>>(id: string, options: ByIdOptions<S, E, Sel> & RequestOptions): Promise<EntityResult<S, E, Sel> | null>;
|
|
170
197
|
upsert(input: UpsertInput<S, E>, options?: MutationRequestOptions): Promise<{
|
|
171
198
|
id: string;
|
|
172
199
|
}>;
|
|
@@ -175,18 +202,76 @@ interface EntityClient<S, E extends EntityName<S>> {
|
|
|
175
202
|
}>;
|
|
176
203
|
}
|
|
177
204
|
type IngestEvents = (events: PyloEventInput[], options?: MutationRequestOptions) => Promise<PyloEvent[]>;
|
|
205
|
+
interface EventsClient {
|
|
206
|
+
list(options?: EventListOptions & RequestOptions): Promise<PyloEventListResult>;
|
|
207
|
+
propertyKeys(options?: PyloEventPropertyKeysOptions & RequestOptions): Promise<PyloEventProperty[]>;
|
|
208
|
+
fieldValues(field: string, options?: PyloEventFieldValuesOptions & RequestOptions): Promise<PyloEventFieldValue[]>;
|
|
209
|
+
}
|
|
178
210
|
type PyloClient<S> = {
|
|
179
211
|
[E in EntityName<S>]: EntityClient<S, E>;
|
|
180
212
|
} & {
|
|
181
213
|
ingestEvents: IngestEvents;
|
|
214
|
+
events: EventsClient;
|
|
182
215
|
};
|
|
183
216
|
|
|
184
217
|
interface NodeClientOptions {
|
|
185
218
|
apiKey: string;
|
|
186
219
|
endpoint?: string;
|
|
187
|
-
schemaMetadata: SchemaMetadata;
|
|
188
220
|
headers?: Record<string, string>;
|
|
189
221
|
}
|
|
190
222
|
declare function createPyloNode<S>(options: NodeClientOptions): PyloClient<S>;
|
|
223
|
+
/**
|
|
224
|
+
* Augmentable registry that lets a host pin the schema type for the injected
|
|
225
|
+
* `pylo` client. Generated code augments it, e.g.:
|
|
226
|
+
*
|
|
227
|
+
* declare module "@pylo/node" {
|
|
228
|
+
* interface PyloRegister { schema: PyloSchema }
|
|
229
|
+
* }
|
|
230
|
+
*
|
|
231
|
+
* With no augmentation the client falls back to an untyped (`any`) schema.
|
|
232
|
+
*/
|
|
233
|
+
interface PyloRegister {
|
|
234
|
+
}
|
|
235
|
+
type RegisteredSchema = PyloRegister extends {
|
|
236
|
+
schema: infer S;
|
|
237
|
+
} ? S : any;
|
|
238
|
+
/**
|
|
239
|
+
* Entity keys available on the registered schema — e.g. `"contact"`. Use as the
|
|
240
|
+
* type parameter for {@link PyloSelect} / {@link PyloResult}.
|
|
241
|
+
*/
|
|
242
|
+
type PyloEntity = EntityName<RegisteredSchema>;
|
|
243
|
+
/**
|
|
244
|
+
* A reusable, type-safe selection for one entity on the registered schema.
|
|
245
|
+
* Lets you define what to fetch once and reuse it across calls.
|
|
246
|
+
*
|
|
247
|
+
* Declare the selection with `satisfies` (not a plain `: PyloSelect<…>`
|
|
248
|
+
* annotation) so the exact set of selected fields is preserved — that's what
|
|
249
|
+
* keeps {@link PyloResult} precise:
|
|
250
|
+
*
|
|
251
|
+
* ```ts
|
|
252
|
+
* const contactSelect = {
|
|
253
|
+
* name: true,
|
|
254
|
+
* email: true,
|
|
255
|
+
* company: { select: { name: true } },
|
|
256
|
+
* } satisfies PyloSelect<"contact">;
|
|
257
|
+
*
|
|
258
|
+
* const { data } = await pylo.contact.list({ select: contactSelect });
|
|
259
|
+
* type Contact = PyloResult<"contact", typeof contactSelect>;
|
|
260
|
+
* ```
|
|
261
|
+
*/
|
|
262
|
+
type PyloSelect<E extends PyloEntity> = EntitySelect<RegisteredSchema, E>;
|
|
263
|
+
/**
|
|
264
|
+
* The row type returned for a given entity and selection. Pair with
|
|
265
|
+
* `typeof <yourSelect>` (see {@link PyloSelect}) for an exact result type.
|
|
266
|
+
*/
|
|
267
|
+
type PyloResult<E extends PyloEntity, Sel extends PyloSelect<E>> = EntityResult<RegisteredSchema, E, Sel>;
|
|
268
|
+
/**
|
|
269
|
+
* Zero-config client for environments that inject a ready-made client onto
|
|
270
|
+
* `globalThis.__PYLO_FLOW_CLIENT__` — e.g. the Pylo flow worker, which builds
|
|
271
|
+
* the client from the flow's API key and the customer's schema before running
|
|
272
|
+
* an action. Property access is forwarded to the current global client at
|
|
273
|
+
* access time, so a worker reused across customers always sees the live one.
|
|
274
|
+
*/
|
|
275
|
+
declare const pylo: PyloClient<RegisteredSchema>;
|
|
191
276
|
|
|
192
|
-
export { type AuthProvider, type ByIdOptions, type ClientOptions, type
|
|
277
|
+
export { type AggregateFunction, type AggregateInput, type AuthProvider, type ByIdOptions, type ClientOptions, type DimensionInput, type EntityClient, type EntityFields, type EntityName, type EntityRelations, type EntityResult, type EntitySelect, type EventListFilterInput, type EventListOptions, type EventsClient, type FilterInput, type IngestEvents, type ListOptions, type ListResult, type MutationRequestOptions, type PaginationData, type PaginationInput, type PyloClient, type PyloEntity, PyloError, type PyloEvent, type PyloEventFieldValue, type PyloEventFieldValuesOptions, type PyloEventInput, type PyloEventListResult, type PyloEventProperty, type PyloEventPropertyKeysOptions, type PyloRegister, type PyloResult, type PyloSelect, type QueryInput, type QueryInputCondition, type QueryOperator, type RegisteredSchema, type RequestOptions, type SearchValueInput, type SortInput, type SortOrder, type StrictSelect, type TimeBucketInput, type UpsertInput, createPyloNode, pylo };
|