@orizm/cli 1.0.2 → 1.0.3

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 (2) hide show
  1. package/dist/cli.js +492 -35
  2. package/package.json +4 -6
package/dist/cli.js CHANGED
@@ -130,7 +130,7 @@ import path from "path";
130
130
  import Handlebars from "handlebars";
131
131
 
132
132
  // src/cms/templates/types.ts.hbr
133
- var types_ts_default = '// This file was automatically generated and should not be edited.\n\nimport { FormValidationRules, StorageItemType } from "@orizm/common";\n\n// Utilities\ntype _ModuleRef<T> = T & _ModuleDescriptor;\ntype _ModuleDescriptor = {\n isModule: true;\n};\ntype _ArrayModuleRef<T> = T & _ArrayModuleDescriptor;\ntype _ArrayModuleDescriptor = {\n isModuleArray: true;\n};\n\n// Tables\n{{#each tables}}\nexport type {{toCodeTypeName this.name}} = {\n id: string;\n createdAt: string;\n updatedAt: string;\n {{#unless this.isSubmissions}}\n group?: string;\n publishedAt?: string;\n _draft?: boolean;\n _published?: boolean;\n scheduledPublishAt?: string | null;\n scheduledUnpublishAt?: string | null;\n {{else}}\n _formId: string;\n _content: unknown;\n _formSchema: unknown;\n _attachments: StorageItemType[];\n {{/unless}}\n {{#each this.columns}}\n {{this.name}}{{#unless this.required}}?{{/unless}}: {{typeName this}};\n {{/each}}\n {{#if this.enableForm}}\n formSchema: FormValidationRules;\n {{/if}}\n};\n\nexport type {{toCodeTypeName this.name}}CreateInput = {\n {{#unless this.isSubmissions}}\n group?: string;\n publishedAt?: string;\n scheduledPublishAt?: string | null;\n scheduledUnpublishAt?: string | null;\n createdAt?: string;\n {{/unless}}\n {{#each this.columns}}\n {{this.name}}{{#unless this.required}}?{{/unless}}: {{typeName this}};\n {{/each}}\n {{#if this.enableForm}}\n formSchema: FormValidationRules;\n {{/if}}\n};\n\nexport type {{toCodeTypeName this.name}}UpdateInput = {\n {{#each this.columns}}\n {{#unless this.readOnly}}{{this.name}}?: {{typeName this}}{{#unless this.required}} | null{{/unless}};{{/unless}}\n {{/each}}\n {{#unless this.isSubmissions}}\n publishedAt?: string;\n scheduledPublishAt?: string | null;\n scheduledUnpublishAt?: string | null;\n createdAt?: string;\n {{/unless}}\n {{#if this.enableForm}}\n formSchema: FormValidationRules;\n {{/if}}\n};\n{{/each}}\n\n// Module types\n{{#each tableModules}}\nexport type {{toCodeTypeName this.name}} = {\n id?: string;\n {{#each this.columns}}\n {{this.name}}{{#unless this.required}}?{{/unless}}: {{typeName this}};\n {{/each}}\n};\n{{/each}}\n\n\n// Descriptor types\n{{#each tables}}\nexport type {{toCodeTypeName this.name}}__Descriptor = {\n row: {{toCodeTypeName this.name}};\n create: {{toCodeTypeName this.name}}CreateInput;\n update: {{toCodeTypeName this.name}}UpdateInput;\n {{#if (filterRefColumn this.columns)}}\n refs: {\n {{#each (filterRefColumn this.columns)}}\n {{includeName this}}: {{{includeType this}}};\n {{/each}}\n }\n {{/if}}\n {{#unless (filterRefColumn this.columns)}}\n refs: object;\n {{/unless}}\n {{#if (filterUniqueIndexes this.indexes)}}\n unique: [\n {{#each (filterUniqueIndexes this.indexes)}}\n { {{#each (getIndexColumns ../this this)}}{{this.name}}:{{typeName this}},{{/each}} },\n {{/each}}\n ]\n {{/if}}\n {{#unless (filterUniqueIndexes this.indexes)}}\n unique: [];\n {{/unless}}\n {{#if this.enableDrafts}}\n enableDrafts: true;\n {{/if}}\n {{#if this.enableForm}}\n submissionDescriptor: {{toCodeTypeName this.name}}_Submission__Descriptor;\n {{else}}\n submissionDescriptor: never;\n {{/if}}\n};\n{{/each}}\n\n\n{{#each tableModules}}\nexport type {{toCodeTypeName this.name}}__Descriptor = {\n row: {{toCodeTypeName this.name}};\n {{#if (filterRefColumn this.columns)}}\n refs: {\n {{#each (filterRefColumn this.columns)}}\n {{includeName this}}: {{{includeType this}}};\n {{/each}}\n }\n {{/if}}\n {{#unless (filterRefColumn this.columns)}}\n refs: object;\n {{/unless}}\n unique:[]\n};\n{{/each}}\n\n\n// Webhook types\nexport type WebhookEvent = "content.create" | "content.update" | "content.delete";\nexport type WebhookPayload = {\n event: WebhookEvent;\n timestamp: string;\n project: string;\n} & (\n {{#each tables}}\n | {\n table: "{{this.name}}";\n content: {{toCodeTypeName this.name}};\n old?: {{toCodeTypeName this.name}};\n }\n {{/each}}\n)\n';
133
+ var types_ts_default = '// This file was automatically generated and should not be edited.\n\nimport { FormValidationRules, StorageItemType } from "@orizm/common";\n\n// Utilities\ntype _ModuleRef<T> = T & _ModuleDescriptor;\ntype _ModuleDescriptor = {\n isModule: true;\n};\ntype _ArrayModuleRef<T> = T & _ArrayModuleDescriptor;\ntype _ArrayModuleDescriptor = {\n isModuleArray: true;\n};\n\n// Tables\n{{#each tables}}\nexport type {{toCodeTypeName this.name}} = {\n id: string;\n createdAt: string;\n updatedAt: string;\n {{#unless this.isSubmissions}}\n group?: string;\n publishedAt?: string;\n _draft?: boolean;\n _published?: boolean;\n scheduledPublishAt?: string | null;\n scheduledUnpublishAt?: string | null;\n {{else}}\n _formId: string;\n _content: unknown;\n _formSchema: unknown;\n _attachments: StorageItemType[];\n {{/unless}}\n {{#each this.columns}}\n {{this.name}}{{#unless this.required}}?{{/unless}}: {{typeName this}};\n {{/each}}\n {{#if this.enableForm}}\n formSchema: FormValidationRules;\n {{/if}}\n};\n\nexport type {{toCodeTypeName this.name}}CreateInput = {\n {{#unless this.isSubmissions}}\n group?: string;\n publishedAt?: string;\n scheduledPublishAt?: string | null;\n scheduledUnpublishAt?: string | null;\n createdAt?: string;\n {{/unless}}\n {{#each this.columns}}\n {{this.name}}{{#unless this.required}}?{{/unless}}: {{typeName this}};\n {{/each}}\n {{#if this.enableForm}}\n formSchema: FormValidationRules;\n {{/if}}\n};\n\nexport type {{toCodeTypeName this.name}}UpdateInput = {\n {{#each this.columns}}\n {{#unless this.readOnly}}{{this.name}}?: {{typeName this}}{{#unless this.required}} | null{{/unless}};{{/unless}}\n {{/each}}\n {{#unless this.isSubmissions}}\n publishedAt?: string;\n scheduledPublishAt?: string | null;\n scheduledUnpublishAt?: string | null;\n createdAt?: string;\n {{/unless}}\n {{#if this.enableForm}}\n formSchema: FormValidationRules;\n {{/if}}\n};\n{{/each}}\n\n// Module types\n{{#each tableModules}}\nexport type {{toCodeTypeName this.name}} = {\n id?: string;\n {{#each this.columns}}\n {{this.name}}{{#unless this.required}}?{{/unless}}: {{typeName this}};\n {{/each}}\n};\n{{/each}}\n\n\n// Descriptor types\n{{#each tables}}\nexport type {{toCodeTypeName this.name}}__Descriptor = {\n row: {{toCodeTypeName this.name}};\n create: {{toCodeTypeName this.name}}CreateInput;\n update: {{toCodeTypeName this.name}}UpdateInput;\n {{#if (filterRefColumn this.columns)}}\n refs: {\n {{#each (filterRefColumn this.columns)}}\n {{includeName this}}: {{{includeType this}}};\n {{/each}}\n }\n {{/if}}\n {{#unless (filterRefColumn this.columns)}}\n refs: object;\n {{/unless}}\n {{#if (filterUniqueIndexes this.indexes)}}\n unique: [\n {{#each (filterUniqueIndexes this.indexes)}}\n { {{#each (getIndexColumns ../this this)}}{{this.name}}:{{typeName this}},{{/each}} },\n {{/each}}\n ]\n {{/if}}\n {{#unless (filterUniqueIndexes this.indexes)}}\n unique: [];\n {{/unless}}\n {{#if this.enableDrafts}}\n enableDrafts: true;\n {{/if}}\n {{#if this.enableForm}}\n submissionDescriptor: {{toCodeTypeName this.name}}_Submission__Descriptor;\n {{else}}\n submissionDescriptor: never;\n {{/if}}\n};\n{{/each}}\n\n\n{{#each tableModules}}\nexport type {{toCodeTypeName this.name}}__Descriptor = {\n row: {{toCodeTypeName this.name}};\n {{#if (filterRefColumn this.columns)}}\n refs: {\n {{#each (filterRefColumn this.columns)}}\n {{includeName this}}: {{{includeType this}}};\n {{/each}}\n }\n {{/if}}\n {{#unless (filterRefColumn this.columns)}}\n refs: object;\n {{/unless}}\n unique:[]\n};\n{{/each}}\n\n\n// Webhook types\nexport type WebhookEvent = "content.create" | "content.update" | "content.delete";\ntype WebhookPayloadBase = {\n event: WebhookEvent;\n timestamp: string;\n project: string;\n};\n{{#if tables}}\nexport type WebhookPayload = WebhookPayloadBase & (\n {{#each tables}}\n | {\n table: "{{this.name}}";\n content: {{toCodeTypeName this.name}};\n old?: {{toCodeTypeName this.name}};\n }\n {{/each}}\n);\n{{else}}\nexport type WebhookPayload = WebhookPayloadBase;\n{{/if}}\n';
134
134
 
135
135
  // src/cms/templates/client.ts.hbr
136
136
  var client_ts_default = '// This file was automatically generated and should not be edited.\n\nimport { OrizmCMSClient } from "@orizm/cms-sdk";\n\nimport * as Models from "./types";\n\nexport class CMSClient {\n constructor(protected client: OrizmCMSClient) {\n this.tables = {\n {{#each tables}}\n {{toEndpointName this.name}}: this.client.getTableClient<Models.{{toCodeTypeName this.name}}__Descriptor>("{{toEndpointName this.name}}"),\n {{/each}}\n };\n\n this.buckets = {\n {{#each buckets}}\n {{toEndpointName this.name}}: this.client.getBucketClient("{{toEndpointName this.name}}"),\n {{/each}}\n };\n\n this.userManagement = this.client.userManagement;\n \n this.userinfo = this.client.userinfo;\n \n this.auth = this.client.auth;\n }\n\n readonly tables;\n readonly buckets;\n readonly userManagement;\n readonly userinfo;\n readonly auth;\n}\n';
@@ -208,7 +208,7 @@ Handlebars.registerHelper(
208
208
  }
209
209
  );
210
210
  async function generate(options) {
211
- const config = options.projectDef;
211
+ const config = options.config;
212
212
  await mkdir(options.output, { recursive: true });
213
213
  await renderTypes(config, options.output);
214
214
  await renderClient(config, options.output);
@@ -238,11 +238,11 @@ var spinner = createSpinner();
238
238
  var cmsGenerateCommand = new Command("generate").description("generate orizm client and types.").option("-c, --config <path>", "orizm config file path.", "orizm.config.ts").option("-o, --output <path>", "output directory.", "./src/orizm").action(async (options) => {
239
239
  try {
240
240
  spinner.start("Loading project schema...");
241
- const projectDef = await loadConfig(options.config);
241
+ const config = await loadConfig(options.config);
242
242
  spinner.succeed("Loaded project schema.");
243
243
  spinner.start("Generating code...");
244
244
  await generate({
245
- projectDef,
245
+ config,
246
246
  output: options.output
247
247
  });
248
248
  spinner.succeed(`Generated code to '${options.output}'`);
@@ -254,36 +254,491 @@ var cmsGenerateCommand = new Command("generate").description("generate orizm cli
254
254
  // src/cms/pull/command.ts
255
255
  import { Command as Command2 } from "commander";
256
256
 
257
- // src/api/developer-api-client.ts
258
- import createClient from "openapi-fetch";
259
- function createDeveloperAPIClient(baseUrl, apiKey) {
260
- const url = new URL(baseUrl);
261
- url.pathname = `/api/dev/v1`;
262
- return createClient({
263
- baseUrl: url.toString(),
264
- headers: {
265
- "x-api-key": apiKey
257
+ // ../../node_modules/.pnpm/openapi-fetch@0.13.5/node_modules/openapi-fetch/dist/index.js
258
+ var PATH_PARAM_RE = /\{[^{}]+\}/g;
259
+ var supportsRequestInitExt = () => {
260
+ return typeof process === "object" && Number.parseInt(process?.versions?.node?.substring(0, 2)) >= 18 && process.versions.undici;
261
+ };
262
+ function randomID() {
263
+ return Math.random().toString(36).slice(2, 11);
264
+ }
265
+ function createClient(clientOptions) {
266
+ let {
267
+ baseUrl = "",
268
+ Request: CustomRequest = globalThis.Request,
269
+ fetch: baseFetch = globalThis.fetch,
270
+ querySerializer: globalQuerySerializer,
271
+ bodySerializer: globalBodySerializer,
272
+ headers: baseHeaders,
273
+ requestInitExt = void 0,
274
+ ...baseOptions
275
+ } = { ...clientOptions };
276
+ requestInitExt = supportsRequestInitExt() ? requestInitExt : void 0;
277
+ baseUrl = removeTrailingSlash(baseUrl);
278
+ const middlewares = [];
279
+ async function coreFetch(schemaPath, fetchOptions) {
280
+ const {
281
+ baseUrl: localBaseUrl,
282
+ fetch = baseFetch,
283
+ Request = CustomRequest,
284
+ headers,
285
+ params = {},
286
+ parseAs = "json",
287
+ querySerializer: requestQuerySerializer,
288
+ bodySerializer = globalBodySerializer ?? defaultBodySerializer,
289
+ body,
290
+ ...init
291
+ } = fetchOptions || {};
292
+ if (localBaseUrl) {
293
+ baseUrl = removeTrailingSlash(localBaseUrl);
294
+ }
295
+ let querySerializer = typeof globalQuerySerializer === "function" ? globalQuerySerializer : createQuerySerializer(globalQuerySerializer);
296
+ if (requestQuerySerializer) {
297
+ querySerializer = typeof requestQuerySerializer === "function" ? requestQuerySerializer : createQuerySerializer({
298
+ ...typeof globalQuerySerializer === "object" ? globalQuerySerializer : {},
299
+ ...requestQuerySerializer
300
+ });
301
+ }
302
+ const serializedBody = body === void 0 ? void 0 : bodySerializer(body);
303
+ const defaultHeaders = (
304
+ // with no body, we should not to set Content-Type
305
+ serializedBody === void 0 || // if serialized body is FormData; browser will correctly set Content-Type & boundary expression
306
+ serializedBody instanceof FormData ? {} : {
307
+ "Content-Type": "application/json"
308
+ }
309
+ );
310
+ const requestInit = {
311
+ redirect: "follow",
312
+ ...baseOptions,
313
+ ...init,
314
+ body: serializedBody,
315
+ headers: mergeHeaders(defaultHeaders, baseHeaders, headers, params.header)
316
+ };
317
+ let id;
318
+ let options;
319
+ let request = new CustomRequest(createFinalURL(schemaPath, { baseUrl, params, querySerializer }), requestInit);
320
+ let response;
321
+ for (const key in init) {
322
+ if (!(key in request)) {
323
+ request[key] = init[key];
324
+ }
325
+ }
326
+ if (middlewares.length) {
327
+ id = randomID();
328
+ options = Object.freeze({
329
+ baseUrl,
330
+ fetch,
331
+ parseAs,
332
+ querySerializer,
333
+ bodySerializer
334
+ });
335
+ for (const m of middlewares) {
336
+ if (m && typeof m === "object" && typeof m.onRequest === "function") {
337
+ const result = await m.onRequest({
338
+ request,
339
+ schemaPath,
340
+ params,
341
+ options,
342
+ id
343
+ });
344
+ if (result) {
345
+ if (result instanceof CustomRequest) {
346
+ request = result;
347
+ } else if (result instanceof Response) {
348
+ response = result;
349
+ break;
350
+ } else {
351
+ throw new Error("onRequest: must return new Request() or Response() when modifying the request");
352
+ }
353
+ }
354
+ }
355
+ }
356
+ }
357
+ if (!response) {
358
+ try {
359
+ response = await fetch(request, requestInitExt);
360
+ } catch (error3) {
361
+ let errorAfterMiddleware = error3;
362
+ if (middlewares.length) {
363
+ for (let i = middlewares.length - 1; i >= 0; i--) {
364
+ const m = middlewares[i];
365
+ if (m && typeof m === "object" && typeof m.onError === "function") {
366
+ const result = await m.onError({
367
+ request,
368
+ error: errorAfterMiddleware,
369
+ schemaPath,
370
+ params,
371
+ options,
372
+ id
373
+ });
374
+ if (result) {
375
+ if (result instanceof Response) {
376
+ errorAfterMiddleware = void 0;
377
+ response = result;
378
+ break;
379
+ }
380
+ if (result instanceof Error) {
381
+ errorAfterMiddleware = result;
382
+ continue;
383
+ }
384
+ throw new Error("onError: must return new Response() or instance of Error");
385
+ }
386
+ }
387
+ }
388
+ }
389
+ if (errorAfterMiddleware) {
390
+ throw errorAfterMiddleware;
391
+ }
392
+ }
393
+ if (middlewares.length) {
394
+ for (let i = middlewares.length - 1; i >= 0; i--) {
395
+ const m = middlewares[i];
396
+ if (m && typeof m === "object" && typeof m.onResponse === "function") {
397
+ const result = await m.onResponse({
398
+ request,
399
+ response,
400
+ schemaPath,
401
+ params,
402
+ options,
403
+ id
404
+ });
405
+ if (result) {
406
+ if (!(result instanceof Response)) {
407
+ throw new Error("onResponse: must return new Response() when modifying the response");
408
+ }
409
+ response = result;
410
+ }
411
+ }
412
+ }
413
+ }
414
+ }
415
+ if (response.status === 204 || response.headers.get("Content-Length") === "0") {
416
+ return response.ok ? { data: void 0, response } : { error: void 0, response };
417
+ }
418
+ if (response.ok) {
419
+ if (parseAs === "stream") {
420
+ return { data: response.body, response };
421
+ }
422
+ return { data: await response[parseAs](), response };
423
+ }
424
+ let error2 = await response.text();
425
+ try {
426
+ error2 = JSON.parse(error2);
427
+ } catch {
428
+ }
429
+ return { error: error2, response };
430
+ }
431
+ return {
432
+ request(method, url, init) {
433
+ return coreFetch(url, { ...init, method: method.toUpperCase() });
434
+ },
435
+ /** Call a GET endpoint */
436
+ GET(url, init) {
437
+ return coreFetch(url, { ...init, method: "GET" });
438
+ },
439
+ /** Call a PUT endpoint */
440
+ PUT(url, init) {
441
+ return coreFetch(url, { ...init, method: "PUT" });
442
+ },
443
+ /** Call a POST endpoint */
444
+ POST(url, init) {
445
+ return coreFetch(url, { ...init, method: "POST" });
446
+ },
447
+ /** Call a DELETE endpoint */
448
+ DELETE(url, init) {
449
+ return coreFetch(url, { ...init, method: "DELETE" });
450
+ },
451
+ /** Call a OPTIONS endpoint */
452
+ OPTIONS(url, init) {
453
+ return coreFetch(url, { ...init, method: "OPTIONS" });
454
+ },
455
+ /** Call a HEAD endpoint */
456
+ HEAD(url, init) {
457
+ return coreFetch(url, { ...init, method: "HEAD" });
458
+ },
459
+ /** Call a PATCH endpoint */
460
+ PATCH(url, init) {
461
+ return coreFetch(url, { ...init, method: "PATCH" });
462
+ },
463
+ /** Call a TRACE endpoint */
464
+ TRACE(url, init) {
465
+ return coreFetch(url, { ...init, method: "TRACE" });
466
+ },
467
+ /** Register middleware */
468
+ use(...middleware) {
469
+ for (const m of middleware) {
470
+ if (!m) {
471
+ continue;
472
+ }
473
+ if (typeof m !== "object" || !("onRequest" in m || "onResponse" in m || "onError" in m)) {
474
+ throw new Error("Middleware must be an object with one of `onRequest()`, `onResponse() or `onError()`");
475
+ }
476
+ middlewares.push(m);
477
+ }
478
+ },
479
+ /** Unregister middleware */
480
+ eject(...middleware) {
481
+ for (const m of middleware) {
482
+ const i = middlewares.indexOf(m);
483
+ if (i !== -1) {
484
+ middlewares.splice(i, 1);
485
+ }
486
+ }
487
+ }
488
+ };
489
+ }
490
+ function serializePrimitiveParam(name, value, options) {
491
+ if (value === void 0 || value === null) {
492
+ return "";
493
+ }
494
+ if (typeof value === "object") {
495
+ throw new Error(
496
+ "Deeply-nested arrays/objects aren\u2019t supported. Provide your own `querySerializer()` to handle these."
497
+ );
498
+ }
499
+ return `${name}=${options?.allowReserved === true ? value : encodeURIComponent(value)}`;
500
+ }
501
+ function serializeObjectParam(name, value, options) {
502
+ if (!value || typeof value !== "object") {
503
+ return "";
504
+ }
505
+ const values = [];
506
+ const joiner = {
507
+ simple: ",",
508
+ label: ".",
509
+ matrix: ";"
510
+ }[options.style] || "&";
511
+ if (options.style !== "deepObject" && options.explode === false) {
512
+ for (const k in value) {
513
+ values.push(k, options.allowReserved === true ? value[k] : encodeURIComponent(value[k]));
514
+ }
515
+ const final2 = values.join(",");
516
+ switch (options.style) {
517
+ case "form": {
518
+ return `${name}=${final2}`;
519
+ }
520
+ case "label": {
521
+ return `.${final2}`;
522
+ }
523
+ case "matrix": {
524
+ return `;${name}=${final2}`;
525
+ }
526
+ default: {
527
+ return final2;
528
+ }
529
+ }
530
+ }
531
+ for (const k in value) {
532
+ const finalName = options.style === "deepObject" ? `${name}[${k}]` : k;
533
+ values.push(serializePrimitiveParam(finalName, value[k], options));
534
+ }
535
+ const final = values.join(joiner);
536
+ return options.style === "label" || options.style === "matrix" ? `${joiner}${final}` : final;
537
+ }
538
+ function serializeArrayParam(name, value, options) {
539
+ if (!Array.isArray(value)) {
540
+ return "";
541
+ }
542
+ if (options.explode === false) {
543
+ const joiner2 = { form: ",", spaceDelimited: "%20", pipeDelimited: "|" }[options.style] || ",";
544
+ const final = (options.allowReserved === true ? value : value.map((v4) => encodeURIComponent(v4))).join(joiner2);
545
+ switch (options.style) {
546
+ case "simple": {
547
+ return final;
548
+ }
549
+ case "label": {
550
+ return `.${final}`;
551
+ }
552
+ case "matrix": {
553
+ return `;${name}=${final}`;
554
+ }
555
+ // case "spaceDelimited":
556
+ // case "pipeDelimited":
557
+ default: {
558
+ return `${name}=${final}`;
559
+ }
560
+ }
561
+ }
562
+ const joiner = { simple: ",", label: ".", matrix: ";" }[options.style] || "&";
563
+ const values = [];
564
+ for (const v4 of value) {
565
+ if (options.style === "simple" || options.style === "label") {
566
+ values.push(options.allowReserved === true ? v4 : encodeURIComponent(v4));
567
+ } else {
568
+ values.push(serializePrimitiveParam(name, v4, options));
569
+ }
570
+ }
571
+ return options.style === "label" || options.style === "matrix" ? `${joiner}${values.join(joiner)}` : values.join(joiner);
572
+ }
573
+ function createQuerySerializer(options) {
574
+ return function querySerializer(queryParams) {
575
+ const search = [];
576
+ if (queryParams && typeof queryParams === "object") {
577
+ for (const name in queryParams) {
578
+ const value = queryParams[name];
579
+ if (value === void 0 || value === null) {
580
+ continue;
581
+ }
582
+ if (Array.isArray(value)) {
583
+ if (value.length === 0) {
584
+ continue;
585
+ }
586
+ search.push(
587
+ serializeArrayParam(name, value, {
588
+ style: "form",
589
+ explode: true,
590
+ ...options?.array,
591
+ allowReserved: options?.allowReserved || false
592
+ })
593
+ );
594
+ continue;
595
+ }
596
+ if (typeof value === "object") {
597
+ search.push(
598
+ serializeObjectParam(name, value, {
599
+ style: "deepObject",
600
+ explode: true,
601
+ ...options?.object,
602
+ allowReserved: options?.allowReserved || false
603
+ })
604
+ );
605
+ continue;
606
+ }
607
+ search.push(serializePrimitiveParam(name, value, options));
608
+ }
266
609
  }
610
+ return search.join("&");
611
+ };
612
+ }
613
+ function defaultPathSerializer(pathname, pathParams) {
614
+ let nextURL = pathname;
615
+ for (const match of pathname.match(PATH_PARAM_RE) ?? []) {
616
+ let name = match.substring(1, match.length - 1);
617
+ let explode = false;
618
+ let style = "simple";
619
+ if (name.endsWith("*")) {
620
+ explode = true;
621
+ name = name.substring(0, name.length - 1);
622
+ }
623
+ if (name.startsWith(".")) {
624
+ style = "label";
625
+ name = name.substring(1);
626
+ } else if (name.startsWith(";")) {
627
+ style = "matrix";
628
+ name = name.substring(1);
629
+ }
630
+ if (!pathParams || pathParams[name] === void 0 || pathParams[name] === null) {
631
+ continue;
632
+ }
633
+ const value = pathParams[name];
634
+ if (Array.isArray(value)) {
635
+ nextURL = nextURL.replace(match, serializeArrayParam(name, value, { style, explode }));
636
+ continue;
637
+ }
638
+ if (typeof value === "object") {
639
+ nextURL = nextURL.replace(match, serializeObjectParam(name, value, { style, explode }));
640
+ continue;
641
+ }
642
+ if (style === "matrix") {
643
+ nextURL = nextURL.replace(match, `;${serializePrimitiveParam(name, value)}`);
644
+ continue;
645
+ }
646
+ nextURL = nextURL.replace(match, style === "label" ? `.${encodeURIComponent(value)}` : encodeURIComponent(value));
647
+ }
648
+ return nextURL;
649
+ }
650
+ function defaultBodySerializer(body) {
651
+ if (body instanceof FormData) {
652
+ return body;
653
+ }
654
+ return JSON.stringify(body);
655
+ }
656
+ function createFinalURL(pathname, options) {
657
+ let finalURL = `${options.baseUrl}${pathname}`;
658
+ if (options.params?.path) {
659
+ finalURL = defaultPathSerializer(finalURL, options.params.path);
660
+ }
661
+ let search = options.querySerializer(options.params.query ?? {});
662
+ if (search.startsWith("?")) {
663
+ search = search.substring(1);
664
+ }
665
+ if (search) {
666
+ finalURL += `?${search}`;
667
+ }
668
+ return finalURL;
669
+ }
670
+ function mergeHeaders(...allHeaders) {
671
+ const finalHeaders = new Headers();
672
+ for (const h of allHeaders) {
673
+ if (!h || typeof h !== "object") {
674
+ continue;
675
+ }
676
+ const iterator = h instanceof Headers ? h.entries() : Object.entries(h);
677
+ for (const [k, v4] of iterator) {
678
+ if (v4 === null) {
679
+ finalHeaders.delete(k);
680
+ } else if (Array.isArray(v4)) {
681
+ for (const v22 of v4) {
682
+ finalHeaders.append(k, v22);
683
+ }
684
+ } else if (v4 !== void 0) {
685
+ finalHeaders.set(k, v4);
686
+ }
687
+ }
688
+ }
689
+ return finalHeaders;
690
+ }
691
+ function removeTrailingSlash(url) {
692
+ if (url.endsWith("/")) {
693
+ return url.substring(0, url.length - 1);
694
+ }
695
+ return url;
696
+ }
697
+
698
+ // ../private-api-clients/src/assert-valid-url-origin.ts
699
+ function assertValidUrlOrigin(origin) {
700
+ const url = new URL(origin);
701
+ if (url.origin !== origin) {
702
+ throw new Error(`${origin} is not a valid URL origin`);
703
+ }
704
+ }
705
+
706
+ // ../private-api-clients/src/dev-v2-api-client.ts
707
+ function createDeveloperAPIv2Client({
708
+ serverOrigin = "",
709
+ fetch,
710
+ headers
711
+ }) {
712
+ if (serverOrigin) assertValidUrlOrigin(serverOrigin);
713
+ return createClient({
714
+ baseUrl: `${serverOrigin}/api/dev/v2`,
715
+ fetch,
716
+ headers
267
717
  });
268
718
  }
269
719
 
270
- // src/lib/fetch-definition-reference.ts
271
- async function fetchDefinitionReference(options) {
272
- const client = createDeveloperAPIClient(options.baseUrl, options.apiKey);
720
+ // src/lib/fetch-current-definition.ts
721
+ async function fetchCurrentDefinition(options) {
722
+ const client = createDeveloperAPIv2Client({
723
+ serverOrigin: options.baseUrl,
724
+ headers: {
725
+ "x-api-key": options.apiKey
726
+ }
727
+ });
273
728
  const abortController = new AbortController();
274
729
  const timeout = setTimeout(() => {
275
730
  abortController.abort();
276
731
  }, 1e4);
277
732
  try {
278
733
  const response = await client.GET(
279
- "/projects/{projectName}/definitions/current/reference",
734
+ "/projects/{projectName}/definitions/current",
280
735
  {
281
736
  params: { path: { projectName: options.projectName } },
282
737
  signal: abortController.signal
283
738
  }
284
739
  );
285
740
  if (response.data) {
286
- return response.data.content;
741
+ return response.data;
287
742
  }
288
743
  if (response.response.status === 404) {
289
744
  throw new Error(`Project ${options.projectName} not found.`);
@@ -365,7 +820,7 @@ async function pullAction(options) {
365
820
  const env = await loadEnv(options.envPath);
366
821
  spinner2.succeed("Loaded environment variables.");
367
822
  spinner2.start("Loading project schema...");
368
- const definitionReference = await fetchDefinitionReference({
823
+ const definitionReference = await fetchCurrentDefinition({
369
824
  baseUrl: env.ORIZM_BASE_URL,
370
825
  apiKey: env.ORIZM_API_KEY,
371
826
  projectName: env.ORIZM_PROJECT
@@ -374,7 +829,7 @@ async function pullAction(options) {
374
829
  spinner2.start("Generating code...");
375
830
  await generate({
376
831
  output: options.destination,
377
- projectDef: definitionReference
832
+ config: definitionReference.parsed
378
833
  });
379
834
  spinner2.succeed(`Generated code to '${options.destination}'`);
380
835
  }
@@ -403,7 +858,7 @@ import Handlebars2 from "handlebars";
403
858
  var client_ts_default2 = '// This file was automatically generated and should not be edited.\n\nimport { ConsumerClientOptions, OrizmConsumerClientBase } from "@orizm/consumer-sdk";\nimport * as Models from "./types";\n\nexport class OrizmClient extends OrizmConsumerClientBase {\n constructor(options: ConsumerClientOptions) {\n super(options);\n }\n\n readonly tables = {\n {{#each tables}}\n {{toEndpointName this.name}}: this.getTableClient<Models.{{toCodeTypeName this.name}}__Descriptor>("{{toEndpointName this.name}}"),\n {{/each}}\n };\n}\n';
404
859
 
405
860
  // src/consumer/templates/types.ts.hbr
406
- var types_ts_default2 = '// This file was automatically generated and should not be edited.\n\nimport { FormValidationRules, StorageItemType } from "@orizm/common";\n\n// Utilities\ntype _ModuleRef<T> = T & _ModuleDescriptor;\ntype _ModuleDescriptor = {\n isModule: true;\n};\ntype _ArrayModuleRef<T> = T & _ArrayModuleDescriptor;\ntype _ArrayModuleDescriptor = {\n isModuleArray: true;\n};\n\n\n// Tables\n{{#each tables}}\nexport type {{toCodeTypeName this.name}} = {\n id: string;\n createdAt: string;\n updatedAt: string;\n group?: string;\n publishedAt?: string;\n _draft?: boolean;\n _published?: boolean;\n {{#each this.columns}}\n {{this.name}}{{#unless this.required}}?{{/unless}}: {{typeName this}};\n {{/each}}\n {{#if this.enableForm}}\n formSchema: FormValidationRules;\n {{/if}}\n}\n\n{{/each}}\n\n{{#each tableModules}}\nexport type {{toCodeTypeName this.name}} = {\n {{#each this.columns}}\n {{this.name}}{{#unless this.required}}?{{/unless}}: {{typeName this}};\n {{/each}}\n};\n{{/each}}\n\n// Descriptor types\n{{#each tables}}\nexport type {{toCodeTypeName this.name}}__Descriptor = {\n row: {{toCodeTypeName this.name}};\n {{#if (filterRefColumn this.columns)}}\n refs: {\n {{#each (filterRefColumn this.columns)}}\n {{includeName this}}: {{{includeType this}}};\n {{/each}}\n }\n {{/if}}\n {{#unless (filterRefColumn this.columns)}}\n refs: object;\n {{/unless}}\n {{#if (filterUniqueIndexes this.indexes)}}\n unique: [\n {{#each (filterUniqueIndexes this.indexes)}}\n { {{#each (getIndexColumns ../this this)}}{{this.name}}:{{typeName this}},{{/each}} },\n {{/each}}\n ]\n {{/if}}\n {{#unless (filterUniqueIndexes this.indexes)}}\n unique: [];\n {{/unless}}\n {{#if this.enableDrafts}}\n enableDrafts: true;\n {{/if}}\n};\n{{/each}}\n\n\n{{#each tableModules}}\nexport type {{toCodeTypeName this.name}}__Descriptor = {\n row: {{toCodeTypeName this.name}};\n {{#if (filterRefColumn this.columns)}}\n refs: {\n {{#each (filterRefColumn this.columns)}}\n {{includeName this}}: {{{includeType this}}};\n {{/each}}\n }\n {{/if}}\n {{#unless (filterRefColumn this.columns)}}\n refs: object;\n {{/unless}}\n unique:[]\n};\n{{/each}}\n\n\n// Webhook types\nexport type WebhookEvent = "content.create" | "content.update" | "content.delete";\nexport type WebhookPayload = {\n event: WebhookEvent;\n timestamp: string;\n project: string;\n} & (\n {{#each tables}}\n | {\n table: "{{this.name}}";\n content: {{toCodeTypeName this.name}};\n old?: {{toCodeTypeName this.name}};\n }\n {{/each}}\n)\n';
861
+ var types_ts_default2 = '// This file was automatically generated and should not be edited.\n\nimport { FormValidationRules, StorageItemType } from "@orizm/common";\n\n// Utilities\ntype _ModuleRef<T> = T & _ModuleDescriptor;\ntype _ModuleDescriptor = {\n isModule: true;\n};\ntype _ArrayModuleRef<T> = T & _ArrayModuleDescriptor;\ntype _ArrayModuleDescriptor = {\n isModuleArray: true;\n};\n\n\n// Tables\n{{#each tables}}\nexport type {{toCodeTypeName this.name}} = {\n id: string;\n createdAt: string;\n updatedAt: string;\n group?: string;\n publishedAt?: string;\n _draft?: boolean;\n _published?: boolean;\n {{#each this.columns}}\n {{this.name}}{{#unless this.required}}?{{/unless}}: {{typeName this}};\n {{/each}}\n {{#if this.enableForm}}\n formSchema: FormValidationRules;\n {{/if}}\n}\n\n{{/each}}\n\n{{#each tableModules}}\nexport type {{toCodeTypeName this.name}} = {\n {{#each this.columns}}\n {{this.name}}{{#unless this.required}}?{{/unless}}: {{typeName this}};\n {{/each}}\n};\n{{/each}}\n\n// Descriptor types\n{{#each tables}}\nexport type {{toCodeTypeName this.name}}__Descriptor = {\n row: {{toCodeTypeName this.name}};\n {{#if (filterRefColumn this.columns)}}\n refs: {\n {{#each (filterRefColumn this.columns)}}\n {{includeName this}}: {{{includeType this}}};\n {{/each}}\n }\n {{/if}}\n {{#unless (filterRefColumn this.columns)}}\n refs: object;\n {{/unless}}\n {{#if (filterUniqueIndexes this.indexes)}}\n unique: [\n {{#each (filterUniqueIndexes this.indexes)}}\n { {{#each (getIndexColumns ../this this)}}{{this.name}}:{{typeName this}},{{/each}} },\n {{/each}}\n ]\n {{/if}}\n {{#unless (filterUniqueIndexes this.indexes)}}\n unique: [];\n {{/unless}}\n {{#if this.enableDrafts}}\n enableDrafts: true;\n {{/if}}\n};\n{{/each}}\n\n\n{{#each tableModules}}\nexport type {{toCodeTypeName this.name}}__Descriptor = {\n row: {{toCodeTypeName this.name}};\n {{#if (filterRefColumn this.columns)}}\n refs: {\n {{#each (filterRefColumn this.columns)}}\n {{includeName this}}: {{{includeType this}}};\n {{/each}}\n }\n {{/if}}\n {{#unless (filterRefColumn this.columns)}}\n refs: object;\n {{/unless}}\n unique:[]\n};\n{{/each}}\n\n\n// Webhook types\nexport type WebhookEvent = "content.create" | "content.update" | "content.delete";\ntype WebhookPayloadBase = {\n event: WebhookEvent;\n timestamp: string;\n project: string;\n};\n{{#if tables}}\nexport type WebhookPayload = WebhookPayloadBase & (\n {{#each tables}}\n | {\n table: "{{this.name}}";\n content: {{toCodeTypeName this.name}};\n old?: {{toCodeTypeName this.name}};\n }\n {{/each}}\n);\n{{else}}\nexport type WebhookPayload = WebhookPayloadBase;\n{{/if}}\n';
407
862
 
408
863
  // src/consumer/pull/generate.ts
409
864
  async function generate2(options) {
@@ -518,7 +973,7 @@ async function pullAction2(options) {
518
973
  const config = await loadEnv(options.envPath);
519
974
  spinner4.succeed("Loaded environment variables.");
520
975
  spinner4.start("Loading project schema...");
521
- const definition = await fetchDefinitionReference({
976
+ const definition = await fetchCurrentDefinition({
522
977
  baseUrl: config.ORIZM_BASE_URL,
523
978
  apiKey: config.ORIZM_API_KEY,
524
979
  projectName: config.ORIZM_PROJECT
@@ -526,7 +981,7 @@ async function pullAction2(options) {
526
981
  spinner4.succeed("Loaded project schema.");
527
982
  spinner4.start("Generating code...");
528
983
  await generate2({
529
- definition,
984
+ definition: definition.parsed,
530
985
  output: options.destination
531
986
  });
532
987
  spinner4.succeed(`Generated code to '${options.destination}'`);
@@ -550,14 +1005,15 @@ import cliColor4 from "cli-color";
550
1005
 
551
1006
  // src/lib/developer-api.ts
552
1007
  async function applyDefinition(env, projectDef) {
553
- const client = createDeveloperAPIClient(
554
- env.ORIZM_BASE_URL,
555
- env.ORIZM_API_KEY
556
- );
1008
+ const client = createDeveloperAPIv2Client({
1009
+ serverOrigin: env.ORIZM_BASE_URL,
1010
+ headers: {
1011
+ "x-api-key": env.ORIZM_API_KEY
1012
+ }
1013
+ });
557
1014
  const response = await client.POST("/projects/{projectName}/definitions", {
558
1015
  params: { path: { projectName: env.ORIZM_PROJECT } },
559
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
560
- body: { apply: true, project: projectDef }
1016
+ body: { definition: projectDef }
561
1017
  });
562
1018
  if (!response.data) {
563
1019
  const status = response.response.status;
@@ -572,16 +1028,17 @@ async function applyDefinition(env, projectDef) {
572
1028
  }
573
1029
  }
574
1030
  var getChangeEvents = async (env, projectDef) => {
575
- const client = createDeveloperAPIClient(
576
- env.ORIZM_BASE_URL,
577
- env.ORIZM_API_KEY
578
- );
1031
+ const client = createDeveloperAPIv2Client({
1032
+ serverOrigin: env.ORIZM_BASE_URL,
1033
+ headers: {
1034
+ "x-api-key": env.ORIZM_API_KEY
1035
+ }
1036
+ });
579
1037
  const response = await client.POST(
580
1038
  "/projects/{projectName}/definitions/dry-run",
581
1039
  {
582
1040
  params: { path: { projectName: env.ORIZM_PROJECT } },
583
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
584
- body: { project: projectDef }
1041
+ body: { definition: projectDef }
585
1042
  }
586
1043
  );
587
1044
  if (!response.data) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@orizm/cli",
3
- "version": "1.0.2",
3
+ "version": "1.0.3",
4
4
  "description": "Orizm CLI",
5
5
  "type": "module",
6
6
  "repository": {
@@ -18,7 +18,6 @@
18
18
  "dotenv": "^16.3.1",
19
19
  "esbuild": "^0.17.19",
20
20
  "handlebars": "^4.7.7",
21
- "openapi-fetch": "^0.12.2",
22
21
  "valibot": "^1.0.0",
23
22
  "@orizm/common": "1.13.1"
24
23
  },
@@ -27,14 +26,13 @@
27
26
  },
28
27
  "devDependencies": {
29
28
  "@types/cli-color": "^2.0.2",
30
- "openapi-typescript": "^7.6.1",
31
- "@orizm/package-configs": "0.0.0"
29
+ "@orizm/package-configs": "0.0.0",
30
+ "@orizm/private-api-clients": "0.0.0"
32
31
  },
33
32
  "license": "Apache-2.0",
34
33
  "scripts": {
35
34
  "dev": "tsup --watch",
36
35
  "build": "tsup",
37
- "typecheck": "tsc --noEmit",
38
- "generate": "openapi-typescript ../../apps/server/openapi/developerAPI.yaml --output src/api/developer-api.d.ts"
36
+ "typecheck": "tsc --noEmit"
39
37
  }
40
38
  }