@osdk/generator 2.8.0-beta.2 → 2.8.0-beta.21

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 (66) hide show
  1. package/CHANGELOG.md +153 -0
  2. package/build/browser/shared/getInterfaceTypesFromQueryDataType.js +3 -0
  3. package/build/browser/shared/getInterfaceTypesFromQueryDataType.js.map +1 -1
  4. package/build/browser/shared/getObjectTypesFromQueryDataType.js +3 -0
  5. package/build/browser/shared/getObjectTypesFromQueryDataType.js.map +1 -1
  6. package/build/browser/util/test/TodoWireOntology.js +20 -10
  7. package/build/browser/util/test/TodoWireOntology.js.map +1 -1
  8. package/build/browser/v2.0/generatePerQueryDataFiles.js +10 -3
  9. package/build/browser/v2.0/generatePerQueryDataFiles.js.map +1 -1
  10. package/build/browser/v2.0/getDescriptionIfPresent.js +4 -1
  11. package/build/browser/v2.0/getDescriptionIfPresent.js.map +1 -1
  12. package/build/cjs/index.cjs +19 -4
  13. package/build/cjs/index.cjs.map +1 -1
  14. package/build/esm/shared/getInterfaceTypesFromQueryDataType.js +3 -0
  15. package/build/esm/shared/getInterfaceTypesFromQueryDataType.js.map +1 -1
  16. package/build/esm/shared/getObjectTypesFromQueryDataType.js +3 -0
  17. package/build/esm/shared/getObjectTypesFromQueryDataType.js.map +1 -1
  18. package/build/esm/util/test/TodoWireOntology.js +20 -10
  19. package/build/esm/util/test/TodoWireOntology.js.map +1 -1
  20. package/build/esm/v2.0/generatePerQueryDataFiles.js +10 -3
  21. package/build/esm/v2.0/generatePerQueryDataFiles.js.map +1 -1
  22. package/build/esm/v2.0/getDescriptionIfPresent.js +4 -1
  23. package/build/esm/v2.0/getDescriptionIfPresent.js.map +1 -1
  24. package/package.json +4 -4
  25. package/build/browser/generateClientSdkPackage.test.js +0 -68
  26. package/build/browser/generateClientSdkPackage.test.js.map +0 -1
  27. package/build/browser/shared/apiNamespaces/startsWithApiNamespace.test.js +0 -47
  28. package/build/browser/shared/apiNamespaces/startsWithApiNamespace.test.js.map +0 -1
  29. package/build/browser/shared/sanitizeMetadata.test.js +0 -46
  30. package/build/browser/shared/sanitizeMetadata.test.js.map +0 -1
  31. package/build/browser/v2.0/UNSTABLE_wireInterfaceTypeV2ToSdkObjectConst.test.js +0 -472
  32. package/build/browser/v2.0/UNSTABLE_wireInterfaceTypeV2ToSdkObjectConst.test.js.map +0 -1
  33. package/build/browser/v2.0/generateClientSdkVersionTwoPointZero.test.js +0 -2603
  34. package/build/browser/v2.0/generateClientSdkVersionTwoPointZero.test.js.map +0 -1
  35. package/build/browser/v2.0/generatePerActionDataFiles.test.js +0 -64
  36. package/build/browser/v2.0/generatePerActionDataFiles.test.js.map +0 -1
  37. package/build/browser/v2.0/generatePerQueryDataFiles.test.js +0 -519
  38. package/build/browser/v2.0/generatePerQueryDataFiles.test.js.map +0 -1
  39. package/build/esm/generateClientSdkPackage.test.js +0 -68
  40. package/build/esm/generateClientSdkPackage.test.js.map +0 -1
  41. package/build/esm/shared/apiNamespaces/startsWithApiNamespace.test.js +0 -47
  42. package/build/esm/shared/apiNamespaces/startsWithApiNamespace.test.js.map +0 -1
  43. package/build/esm/shared/sanitizeMetadata.test.js +0 -46
  44. package/build/esm/shared/sanitizeMetadata.test.js.map +0 -1
  45. package/build/esm/v2.0/UNSTABLE_wireInterfaceTypeV2ToSdkObjectConst.test.js +0 -472
  46. package/build/esm/v2.0/UNSTABLE_wireInterfaceTypeV2ToSdkObjectConst.test.js.map +0 -1
  47. package/build/esm/v2.0/generateClientSdkVersionTwoPointZero.test.js +0 -2603
  48. package/build/esm/v2.0/generateClientSdkVersionTwoPointZero.test.js.map +0 -1
  49. package/build/esm/v2.0/generatePerActionDataFiles.test.js +0 -64
  50. package/build/esm/v2.0/generatePerActionDataFiles.test.js.map +0 -1
  51. package/build/esm/v2.0/generatePerQueryDataFiles.test.js +0 -519
  52. package/build/esm/v2.0/generatePerQueryDataFiles.test.js.map +0 -1
  53. package/build/types/generateClientSdkPackage.test.d.ts +0 -1
  54. package/build/types/generateClientSdkPackage.test.d.ts.map +0 -1
  55. package/build/types/shared/apiNamespaces/startsWithApiNamespace.test.d.ts +0 -1
  56. package/build/types/shared/apiNamespaces/startsWithApiNamespace.test.d.ts.map +0 -1
  57. package/build/types/shared/sanitizeMetadata.test.d.ts +0 -1
  58. package/build/types/shared/sanitizeMetadata.test.d.ts.map +0 -1
  59. package/build/types/v2.0/UNSTABLE_wireInterfaceTypeV2ToSdkObjectConst.test.d.ts +0 -1
  60. package/build/types/v2.0/UNSTABLE_wireInterfaceTypeV2ToSdkObjectConst.test.d.ts.map +0 -1
  61. package/build/types/v2.0/generateClientSdkVersionTwoPointZero.test.d.ts +0 -1
  62. package/build/types/v2.0/generateClientSdkVersionTwoPointZero.test.d.ts.map +0 -1
  63. package/build/types/v2.0/generatePerActionDataFiles.test.d.ts +0 -1
  64. package/build/types/v2.0/generatePerActionDataFiles.test.d.ts.map +0 -1
  65. package/build/types/v2.0/generatePerQueryDataFiles.test.d.ts +0 -1
  66. package/build/types/v2.0/generatePerQueryDataFiles.test.d.ts.map +0 -1
@@ -1,2603 +0,0 @@
1
- /*
2
- * Copyright 2023 Palantir Technologies, Inc. All rights reserved.
3
- *
4
- * Licensed under the Apache License, Version 2.0 (the "License");
5
- * you may not use this file except in compliance with the License.
6
- * You may obtain a copy of the License at
7
- *
8
- * http://www.apache.org/licenses/LICENSE-2.0
9
- *
10
- * Unless required by applicable law or agreed to in writing, software
11
- * distributed under the License is distributed on an "AS IS" BASIS,
12
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
- * See the License for the specific language governing permissions and
14
- * limitations under the License.
15
- */
16
-
17
- import { consola } from "consola";
18
- import { mkdir, readdir, rmdir, writeFile } from "fs/promises";
19
- import * as immer from "immer";
20
- import { beforeEach, describe, expect, it, test, vi } from "vitest";
21
- import { compileThis } from "../util/test/compileThis.js";
22
- import { createMockMinimalFiles } from "../util/test/createMockMinimalFiles.js";
23
- import { TodoWireOntology } from "../util/test/TodoWireOntology.js";
24
- import { generateClientSdkVersionTwoPointZero } from "./generateClientSdkVersionTwoPointZero.js";
25
- function changeValue(draft, key, oldValue, newValue) {
26
- if (draft[key] === oldValue) {
27
- draft[key] = newValue;
28
- }
29
- }
30
- function changeKey(draft, oldInterfaceName, newInterfaceName) {
31
- if (draft[oldInterfaceName]) {
32
- draft[newInterfaceName] = draft[oldInterfaceName];
33
- delete draft[oldInterfaceName];
34
- }
35
- }
36
- function changeArrayEntry(draft, oldNew, newName) {
37
- const idx = draft.findIndex(a => a === oldNew);
38
- if (idx >= 0) {
39
- draft[idx] = newName;
40
- }
41
- }
42
- function changeEachEntry(wireData, data, changer, changeSelf) {
43
- for (const [oldName, newName] of Object.entries(data)) {
44
- for (const k of Object.keys(wireData)) {
45
- changer(wireData[k], oldName, newName);
46
- if (changeSelf && k === oldName) {
47
- wireData[newName] = wireData[k];
48
- delete wireData[k];
49
- }
50
- }
51
- }
52
- }
53
- function changeDataType(dataType, oldObjectName, newObjectName) {
54
- if (dataType.type === "array") {
55
- changeDataType(dataType.subType, oldObjectName, newObjectName);
56
- } else if (dataType.type === "object" || dataType.type === "objectSet") {
57
- if (dataType.objectTypeApiName === oldObjectName) {
58
- dataType.objectTypeApiName = newObjectName;
59
- }
60
- if (dataType.objectApiName === oldObjectName) {
61
- dataType.objectApiName = newObjectName;
62
- }
63
- }
64
- }
65
- function changeNames(ontology, newNames) {
66
- return immer.produce(ontology, draft => {
67
- // Handle spt renames
68
- changeEachEntry(draft.sharedPropertyTypes, newNames.spts, (draft, oldSptName, newSptName) => {
69
- changeValue(draft, "apiName", oldSptName, newSptName);
70
- }, true);
71
-
72
- // Handle query renames
73
- changeEachEntry(draft.queryTypes, newNames.queries, (draft, oldActionName, newActionName) => {
74
- if (draft.apiName === oldActionName) {
75
- draft.apiName = newActionName;
76
- }
77
- }, true);
78
-
79
- // Handle action renames
80
- changeEachEntry(draft.actionTypes, newNames.actions, (draft, oldActionName, newActionName) => {
81
- changeValue(draft, "apiName", oldActionName, newActionName);
82
- }, true);
83
-
84
- // Handle interface renames
85
- changeEachEntry(draft.interfaceTypes, newNames.interfaces, (ifaceType, oldIfaceName, newIfaceName) => {
86
- changeValue(ifaceType, "apiName", oldIfaceName, newIfaceName);
87
- ifaceType.extendsInterfaces = ifaceType.allExtendsInterfaces.map(v => v === oldIfaceName ? newIfaceName : v);
88
- changeEachEntry(ifaceType.allProperties, newNames.spts, (property, oldSptName, newSptName) => {
89
- changeValue(property, "apiName", oldSptName, newSptName);
90
- }, true);
91
- }, true);
92
- changeEachEntry(draft.objectTypes, newNames.interfaces, (objectType, oldIfaceName, newIfaceName) => {
93
- changeArrayEntry(objectType.implementsInterfaces, oldIfaceName, newIfaceName);
94
- changeKey(objectType.implementsInterfaces2, oldIfaceName, newIfaceName);
95
- });
96
-
97
- // Handle object renames
98
- changeEachEntry(draft.queryTypes, newNames.objects, (queryType, oldObjectName, newObjectName) => {
99
- changeDataType(queryType.output, oldObjectName, newObjectName);
100
- for (const {
101
- dataType
102
- } of Object.values(queryType.parameters)) {
103
- changeDataType(dataType, oldObjectName, newObjectName);
104
- }
105
- });
106
- changeEachEntry(draft.objectTypes, newNames.objects, ({
107
- objectType,
108
- linkTypes
109
- }, oldObjectName, newObjectName) => {
110
- changeValue(objectType, "apiName", oldObjectName, newObjectName);
111
- for (const l of linkTypes) {
112
- changeValue(l, "objectTypeApiName", oldObjectName, newObjectName);
113
- }
114
- }, true);
115
- changeEachEntry(draft.actionTypes, newNames.objects, (action, oldObjectName, newObjectName) => {
116
- for (const op of action.operations) {
117
- switch (op.type) {
118
- case "deleteObject":
119
- case "modifyObject":
120
- case "createObject":
121
- if (op.objectTypeApiName === oldObjectName) {
122
- op.objectTypeApiName = newObjectName;
123
- }
124
- }
125
- }
126
- for (const {
127
- dataType
128
- } of Object.values(action.parameters)) {
129
- changeDataType(dataType, oldObjectName, newObjectName);
130
- }
131
- });
132
- });
133
- }
134
- const referencedOntology = {
135
- "ontology": {
136
- "apiName": "dep",
137
- "rid": "ri.ontology.main.ontology.dep",
138
- "displayName": "",
139
- "description": ""
140
- },
141
- "actionTypes": {},
142
- "objectTypes": {
143
- "com.example.dep.Task": {
144
- implementsInterfaces: [],
145
- implementsInterfaces2: {},
146
- sharedPropertyTypeMapping: {},
147
- "objectType": {
148
- "apiName": "com.example.dep.Task",
149
- "primaryKey": "taskId",
150
- displayName: "Task",
151
- pluralDisplayName: "Tasks",
152
- icon: {
153
- type: "blueprint",
154
- color: "blue",
155
- name: "document"
156
- },
157
- titleProperty: "taskId",
158
- "properties": {
159
- "taskId": {
160
- "dataType": {
161
- "type": "string"
162
- },
163
- "rid": "ridForTaskId"
164
- },
165
- "body": {
166
- "dataType": {
167
- "type": "string"
168
- },
169
- "rid": "ridForBody"
170
- },
171
- "shouldBeIgnored": {
172
- "dataType": {
173
- "type": "futureUnknownType"
174
- },
175
- "rid": "ridForShouldBeIgnored"
176
- }
177
- },
178
- "status": "ACTIVE",
179
- "rid": "ridForTask"
180
- },
181
- "linkTypes": []
182
- }
183
- },
184
- "queryTypes": {},
185
- "interfaceTypes": {
186
- "com.example.dep.SomeInterface": {
187
- apiName: "com.example.dep.SomeInterface",
188
- rid: "idk2",
189
- displayName: "Sum Interface",
190
- extendsInterfaces: [],
191
- properties: {
192
- "com.example.dep.spt": {
193
- apiName: "com.example.dep.spt",
194
- dataType: {
195
- type: "string"
196
- },
197
- displayName: "Some Property",
198
- rid: "idk",
199
- required: true
200
- }
201
- },
202
- propertiesV2: {},
203
- implementedByObjectTypes: [],
204
- links: {},
205
- allExtendsInterfaces: [],
206
- allLinks: {},
207
- allProperties: {
208
- "com.example.dep.spt": {
209
- apiName: "com.example.dep.spt",
210
- dataType: {
211
- type: "string"
212
- },
213
- displayName: "Some Property",
214
- rid: "idk",
215
- required: true
216
- },
217
- "com.example.dep.spt2": {
218
- apiName: "com.example.dep.spt2",
219
- dataType: {
220
- type: "string"
221
- },
222
- displayName: "Some Property 2",
223
- rid: "idk",
224
- required: true
225
- }
226
- },
227
- allPropertiesV2: {}
228
- }
229
- },
230
- "sharedPropertyTypes": {
231
- "com.example.dep.spt": {
232
- apiName: "com.example.dep.spt",
233
- dataType: {
234
- type: "string"
235
- },
236
- displayName: "Some Property",
237
- rid: "idk"
238
- }
239
- },
240
- "branch": {
241
- rid: "someRidHere"
242
- },
243
- valueTypes: {}
244
- };
245
- const referencingOntology = {
246
- ontology: TodoWireOntology.ontology,
247
- "actionTypes": {
248
- "setTaskBody": {
249
- "apiName": "setTaskBody",
250
- "parameters": {
251
- "task": {
252
- "displayName": "taskBody",
253
- "dataType": {
254
- "type": "object",
255
- "objectApiName": "com.example.dep.Task",
256
- "objectTypeApiName": "com.example.dep.Task"
257
- },
258
- "required": true
259
- },
260
- "body": {
261
- "displayName": "body",
262
- "dataType": {
263
- "type": "string"
264
- },
265
- "required": true
266
- }
267
- },
268
- "status": "ACTIVE",
269
- "rid": "ri.a.b.c.d",
270
- "operations": [{
271
- "type": "modifyObject",
272
- "objectTypeApiName": "com.example.dep.Task"
273
- }]
274
- }
275
- },
276
- interfaceTypes: {
277
- ...referencedOntology.interfaceTypes
278
- },
279
- objectTypes: {
280
- ...referencedOntology.objectTypes,
281
- "Thing": {
282
- implementsInterfaces: ["com.example.dep.SomeInterface"],
283
- implementsInterfaces2: {
284
- "com.example.dep.SomeInterface": {
285
- links: {},
286
- properties: {
287
- "com.example.dep.spt": "body"
288
- },
289
- propertiesV2: {}
290
- }
291
- },
292
- linkTypes: [],
293
- objectType: {
294
- apiName: "Thing",
295
- displayName: "Thing",
296
- pluralDisplayName: "Things",
297
- icon: {
298
- type: "blueprint",
299
- color: "blue",
300
- name: "document"
301
- },
302
- primaryKey: "id",
303
- properties: {
304
- "id": {
305
- dataType: {
306
- type: "integer"
307
- },
308
- rid: "rid"
309
- },
310
- "body": {
311
- dataType: {
312
- type: "string"
313
- },
314
- "rid": "rid"
315
- }
316
- },
317
- rid: "ridForThing",
318
- status: "ACTIVE",
319
- titleProperty: "id"
320
- },
321
- sharedPropertyTypeMapping: {}
322
- },
323
- "UsesForeignSpt": {
324
- implementsInterfaces: [],
325
- implementsInterfaces2: {},
326
- linkTypes: [],
327
- objectType: {
328
- apiName: "UsesForeignSpt",
329
- primaryKey: "id",
330
- displayName: "Uses Foreign Spt",
331
- icon: {
332
- type: "blueprint",
333
- color: "blue",
334
- name: "document"
335
- },
336
- pluralDisplayName: "Uses Foreign Spts",
337
- properties: {
338
- "id": {
339
- dataType: {
340
- type: "integer"
341
- },
342
- rid: "rid"
343
- },
344
- "body": {
345
- dataType: {
346
- type: "string"
347
- },
348
- rid: "rid"
349
- }
350
- },
351
- rid: "theRid",
352
- status: "ACTIVE",
353
- titleProperty: "id"
354
- },
355
- sharedPropertyTypeMapping: {
356
- "com.example.dep.spt": "body"
357
- }
358
- }
359
- },
360
- queryTypes: {
361
- getTask: {
362
- apiName: "getTask",
363
- output: {
364
- type: "object",
365
- objectApiName: "com.example.dep.Task",
366
- objectTypeApiName: "com.example.dep.Task"
367
- },
368
- parameters: {
369
- "a": {
370
- dataType: {
371
- type: "object",
372
- objectApiName: "com.example.dep.Task",
373
- objectTypeApiName: "com.example.dep.Task"
374
- }
375
- }
376
- },
377
- rid: "ri.a.b.c",
378
- version: "0"
379
- }
380
- },
381
- sharedPropertyTypes: {},
382
- valueTypes: {}
383
- };
384
- const fooBarTodoWireOntology = changeNames(TodoWireOntology, {
385
- objects: {
386
- "Todo": "foo.bar.Todo",
387
- "Person": "foo.bar.Person"
388
- },
389
- actions: {
390
- markTodoCompleted: "foo.bar.markTodoCompleted",
391
- deleteTodos: "foo.bar.deleteTodos"
392
- },
393
- interfaces: {
394
- "SomeInterface": "foo.bar.SomeInterface"
395
- },
396
- queries: {
397
- "getCount": "foo.bar.getCount",
398
- "returnsTodo": "foo.bar.returnsTodo"
399
- },
400
- spts: {
401
- "SomeProperty": "foo.bar.SomeProperty"
402
- }
403
- });
404
- const BASE_PATH = "/foo";
405
- describe("generator", () => {
406
- let helper;
407
- beforeEach(async () => {
408
- helper = createMockMinimalFiles();
409
- });
410
- test("should be able to generate a project", {
411
- timeout: 20_000
412
- }, async () => {
413
- await generateClientSdkVersionTwoPointZero(TodoWireOntology, "typescript-sdk/0.0.0 osdk-cli/0.0.0", helper.minimalFiles, BASE_PATH);
414
- const files = helper.getFiles();
415
- expect(files).toMatchObject({
416
- [`${BASE_PATH}/index.ts`]: expect.anything(),
417
- [`${BASE_PATH}/OntologyMetadata.ts`]: expect.anything(),
418
- [`${BASE_PATH}/ontology/objects/Todo.ts`]: expect.anything()
419
- });
420
- const diagnostics = compileThis(helper.getFiles(), BASE_PATH);
421
- for (const q of diagnostics) {
422
- console.error(`${q.file?.fileName}:${q.file?.getLineStarts()}`, q.messageText);
423
- }
424
-
425
- // TODO: Certain errors are expected since we can't resolve the static code, but we should fix them.
426
- const errors = diagnostics.filter(q => q.code !== 2792);
427
- expect(errors).toHaveLength(0);
428
- expect(tweakedFilesForSnapshotConsistency(helper.getFiles())).toMatchInlineSnapshot(`
429
- {
430
- "/foo/OntologyMetadata.ts": "export type $ExpectedClientVersion = 'PLACEHOLDER';
431
- export const $osdkMetadata = { extraUserAgent: 'typescript-sdk/0.0.0 osdk-cli/0.0.0' };
432
-
433
- export const $ontologyRid = 'ridHere';
434
- ",
435
- "/foo/index.ts": "export { deleteTodos, markTodoCompleted } from './ontology/actions.js';
436
- export * as $Actions from './ontology/actions.js';
437
- export { SomeInterface } from './ontology/interfaces.js';
438
- export * as $Interfaces from './ontology/interfaces.js';
439
- export { Person, Todo } from './ontology/objects.js';
440
- export * as $Objects from './ontology/objects.js';
441
- export { getCount, returnsTodo } from './ontology/queries.js';
442
- export * as $Queries from './ontology/queries.js';
443
- export { $osdkMetadata } from './OntologyMetadata.js';
444
- export { $ontologyRid } from './OntologyMetadata.js';
445
- ",
446
- "/foo/ontology/actions.ts": "export { deleteTodos } from './actions/deleteTodos.js';
447
- export { markTodoCompleted } from './actions/markTodoCompleted.js';
448
- ",
449
- "/foo/ontology/actions/deleteTodos.ts": "import type {
450
- ActionDefinition,
451
- ActionMetadata,
452
- ActionParam,
453
- ActionReturnTypeForOptions,
454
- ApplyActionOptions,
455
- ApplyBatchActionOptions,
456
- } from '@osdk/client';
457
- import { $osdkMetadata } from '../../OntologyMetadata.js';
458
- import type { Todo } from '../objects/Todo.js';
459
-
460
- export namespace deleteTodos {
461
- // Represents the definition of the parameters for the action
462
- export type ParamsDefinition = {
463
- object: {
464
- description: 'Todo(s) to be deleted';
465
- multiplicity: true;
466
- nullable: true;
467
- type: ActionMetadata.DataType.Object<Todo>;
468
- };
469
- };
470
-
471
- /**
472
- * An action which takes in an array of objects
473
- */
474
- export interface Params {
475
- /**
476
- * Todo(s) to be deleted
477
- */
478
- readonly object?: ReadonlyArray<ActionParam.ObjectType<Todo>> | null;
479
- }
480
-
481
- // Represents a fqn of the action
482
- export interface Signatures {
483
- /**
484
- * An action which takes in an array of objects
485
- */
486
- applyAction<OP extends ApplyActionOptions>(
487
- args: deleteTodos.Params,
488
- options?: OP,
489
- ): Promise<ActionReturnTypeForOptions<OP>>;
490
-
491
- batchApplyAction<OP extends ApplyBatchActionOptions>(
492
- args: ReadonlyArray<deleteTodos.Params>,
493
- options?: OP,
494
- ): Promise<ActionReturnTypeForOptions<OP>>;
495
- }
496
- }
497
-
498
- /**
499
- * An action which takes in an array of objects
500
- *
501
- * **Note on null values:** _For optional parameters, explicitly providing a null value instead of undefined
502
- * can change the behavior of the applied action. If prefills are configured, null prevents them
503
- * from being applied. If a parameter modifies an object's property, null will clear the data from
504
- * the object, whereas undefined would not modify that property._
505
- * @param {ActionParam.ObjectType<Todo>} [object] Todo(s) to be deleted
506
- */
507
- export interface deleteTodos extends ActionDefinition<deleteTodos.Signatures> {
508
- __DefinitionMetadata?: {
509
- apiName: 'deleteTodos';
510
- description: 'An action which takes in an array of objects';
511
- modifiedEntities: {};
512
- parameters: deleteTodos.ParamsDefinition;
513
- rid: 'ri.ontology.main.action-type.8f94017d-cf17-4fa8-84c3-8e01e5d594f2';
514
- status: 'ACTIVE';
515
- type: 'action';
516
-
517
- signatures: deleteTodos.Signatures;
518
- };
519
- apiName: 'deleteTodos';
520
- type: 'action';
521
- osdkMetadata: typeof $osdkMetadata;
522
- }
523
-
524
- export const deleteTodos: deleteTodos = {
525
- apiName: 'deleteTodos',
526
- type: 'action',
527
- osdkMetadata: $osdkMetadata,
528
- };
529
- ",
530
- "/foo/ontology/actions/markTodoCompleted.ts": "import type {
531
- ActionDefinition,
532
- ActionMetadata,
533
- ActionParam,
534
- ActionReturnTypeForOptions,
535
- ApplyActionOptions,
536
- ApplyBatchActionOptions,
537
- } from '@osdk/client';
538
- import { $osdkMetadata } from '../../OntologyMetadata.js';
539
- import type { Todo } from '../objects/Todo.js';
540
-
541
- export namespace markTodoCompleted {
542
- // Represents the definition of the parameters for the action
543
- export type ParamsDefinition = {
544
- object: {
545
- description: 'A Todo to mark completed';
546
- multiplicity: false;
547
- nullable: true;
548
- type: ActionMetadata.DataType.Object<Todo>;
549
- };
550
- };
551
-
552
- /**
553
- * An action which takes different types of parameters
554
- */
555
- export interface Params {
556
- /**
557
- * A Todo to mark completed
558
- */
559
- readonly object?: ActionParam.ObjectType<Todo> | null;
560
- }
561
-
562
- // Represents a fqn of the action
563
- export interface Signatures {
564
- /**
565
- * An action which takes different types of parameters
566
- */
567
- applyAction<OP extends ApplyActionOptions>(
568
- args: markTodoCompleted.Params,
569
- options?: OP,
570
- ): Promise<ActionReturnTypeForOptions<OP>>;
571
-
572
- batchApplyAction<OP extends ApplyBatchActionOptions>(
573
- args: ReadonlyArray<markTodoCompleted.Params>,
574
- options?: OP,
575
- ): Promise<ActionReturnTypeForOptions<OP>>;
576
- }
577
- }
578
-
579
- /**
580
- * An action which takes different types of parameters
581
- *
582
- * **Note on null values:** _For optional parameters, explicitly providing a null value instead of undefined
583
- * can change the behavior of the applied action. If prefills are configured, null prevents them
584
- * from being applied. If a parameter modifies an object's property, null will clear the data from
585
- * the object, whereas undefined would not modify that property._
586
- * @param {ActionParam.ObjectType<Todo>} [object] A Todo to mark completed
587
- */
588
- export interface markTodoCompleted extends ActionDefinition<markTodoCompleted.Signatures> {
589
- __DefinitionMetadata?: {
590
- apiName: 'markTodoCompleted';
591
- description: 'An action which takes different types of parameters';
592
- modifiedEntities: {
593
- Todo: {
594
- created: false;
595
- modified: true;
596
- };
597
- };
598
- parameters: markTodoCompleted.ParamsDefinition;
599
- rid: 'ri.ontology.main.action-type.9f84017d-cf17-4fa8-84c3-8e01e5d594f2';
600
- status: 'ACTIVE';
601
- type: 'action';
602
-
603
- signatures: markTodoCompleted.Signatures;
604
- };
605
- apiName: 'markTodoCompleted';
606
- type: 'action';
607
- osdkMetadata: typeof $osdkMetadata;
608
- }
609
-
610
- export const markTodoCompleted: markTodoCompleted = {
611
- apiName: 'markTodoCompleted',
612
- type: 'action',
613
- osdkMetadata: $osdkMetadata,
614
- };
615
- ",
616
- "/foo/ontology/interfaces.ts": "export { SomeInterface } from './interfaces/SomeInterface.js';
617
- ",
618
- "/foo/ontology/interfaces/SomeInterface.ts": "import type { PropertyDef as $PropertyDef } from '@osdk/client';
619
- import { $osdkMetadata } from '../../OntologyMetadata.js';
620
-
621
- import type {
622
- InterfaceDefinition as $InterfaceDefinition,
623
- InterfaceMetadata as $InterfaceMetadata,
624
- ObjectSet as $ObjectSet,
625
- Osdk as $Osdk,
626
- PropertyValueWireToClient as $PropType,
627
- } from '@osdk/client';
628
-
629
- export type OsdkObjectLinks$SomeInterface = {};
630
-
631
- export namespace SomeInterface {
632
- export type PropertyKeys = 'SomeProperty';
633
-
634
- export interface Props {
635
- /**
636
- * display name: 'Sum Property',
637
- *
638
- * description: Some property
639
- */
640
- readonly SomeProperty: $PropType['string'] | undefined;
641
- }
642
- export type StrictProps = Props;
643
-
644
- export interface ObjectSet extends $ObjectSet<SomeInterface, SomeInterface.ObjectSet> {}
645
-
646
- export type OsdkInstance<
647
- OPTIONS extends never | '$rid' = never,
648
- K extends keyof SomeInterface.Props = keyof SomeInterface.Props,
649
- > = $Osdk.Instance<SomeInterface, OPTIONS, K>;
650
-
651
- /** @deprecated use OsdkInstance */
652
- export type OsdkObject<
653
- OPTIONS extends never | '$rid' = never,
654
- K extends keyof SomeInterface.Props = keyof SomeInterface.Props,
655
- > = OsdkInstance<OPTIONS, K>;
656
- }
657
-
658
- export interface SomeInterface extends $InterfaceDefinition {
659
- osdkMetadata: typeof $osdkMetadata;
660
- type: 'interface';
661
- apiName: 'SomeInterface';
662
- __DefinitionMetadata?: {
663
- objectSet: SomeInterface.ObjectSet;
664
- props: SomeInterface.Props;
665
- linksType: OsdkObjectLinks$SomeInterface;
666
- strictProps: SomeInterface.StrictProps;
667
- apiName: 'SomeInterface';
668
- description: 'Some interface';
669
- displayName: 'Sum Interface';
670
- implementedBy: [];
671
- implements: [];
672
- links: {};
673
- properties: {
674
- /**
675
- * display name: 'Sum Property',
676
- *
677
- * description: Some property
678
- */
679
- SomeProperty: $PropertyDef<'string', 'nullable', 'single'>;
680
- };
681
- rid: 'idk';
682
- type: 'interface';
683
- };
684
- }
685
-
686
- export const SomeInterface = {
687
- type: 'interface',
688
- apiName: 'SomeInterface',
689
- osdkMetadata: $osdkMetadata,
690
- internalDoNotUseMetadata: {
691
- rid: 'idk',
692
- },
693
- } satisfies SomeInterface & { internalDoNotUseMetadata: { rid: string } } as SomeInterface;
694
- ",
695
- "/foo/ontology/objects.ts": "export { Person } from './objects/Person.js';
696
- export { Todo } from './objects/Todo.js';
697
- ",
698
- "/foo/ontology/objects/Person.ts": "import type { PropertyDef as $PropertyDef } from '@osdk/client';
699
- import { $osdkMetadata } from '../../OntologyMetadata.js';
700
- import type { $ExpectedClientVersion } from '../../OntologyMetadata.js';
701
- import type { Todo } from './Todo.js';
702
- import type {
703
- PropertyKeys as $PropertyKeys,
704
- ObjectTypeDefinition as $ObjectTypeDefinition,
705
- ObjectMetadata as $ObjectMetadata,
706
- } from '@osdk/client';
707
- import type {
708
- ObjectSet as $ObjectSet,
709
- Osdk as $Osdk,
710
- OsdkObject as $OsdkObject,
711
- PropertyValueWireToClient as $PropType,
712
- SingleLinkAccessor as $SingleLinkAccessor,
713
- } from '@osdk/client';
714
-
715
- export namespace Person {
716
- export type PropertyKeys = 'email';
717
-
718
- export interface Links {
719
- readonly Todos: Todo.ObjectSet;
720
- }
721
-
722
- export interface Props {
723
- /**
724
- * (no ontology metadata)
725
- */
726
- readonly email: 'osdk@palantir.com' | 'foundry@palantir.com';
727
- }
728
- export type StrictProps = Props;
729
-
730
- export interface ObjectSet extends $ObjectSet<Person, Person.ObjectSet> {}
731
-
732
- export type OsdkInstance<
733
- OPTIONS extends never | '$rid' = never,
734
- K extends keyof Person.Props = keyof Person.Props,
735
- > = $Osdk.Instance<Person, OPTIONS, K>;
736
-
737
- /** @deprecated use OsdkInstance */
738
- export type OsdkObject<
739
- OPTIONS extends never | '$rid' = never,
740
- K extends keyof Person.Props = keyof Person.Props,
741
- > = OsdkInstance<OPTIONS, K>;
742
- }
743
-
744
- export interface Person extends $ObjectTypeDefinition {
745
- osdkMetadata: typeof $osdkMetadata;
746
- type: 'object';
747
- apiName: 'Person';
748
- __DefinitionMetadata?: {
749
- objectSet: Person.ObjectSet;
750
- props: Person.Props;
751
- linksType: Person.Links;
752
- strictProps: Person.StrictProps;
753
- apiName: 'Person';
754
- description: 'A person';
755
- displayName: 'Person';
756
- icon: {
757
- type: 'blueprint';
758
- name: 'document';
759
- color: 'blue';
760
- };
761
- implements: [];
762
- interfaceMap: {};
763
- inverseInterfaceMap: {};
764
- links: {
765
- Todos: $ObjectMetadata.Link<Todo, true>;
766
- };
767
- pluralDisplayName: 'Persons';
768
- primaryKeyApiName: 'email';
769
- primaryKeyType: 'string';
770
- properties: {
771
- /**
772
- * (no ontology metadata)
773
- */
774
- email: $PropertyDef<'string', 'non-nullable', 'single'>;
775
- };
776
- rid: 'ridForPerson';
777
- status: 'ACTIVE';
778
- titleProperty: 'email';
779
- type: 'object';
780
- visibility: undefined;
781
- };
782
- }
783
-
784
- export const Person = {
785
- type: 'object',
786
- apiName: 'Person',
787
- osdkMetadata: $osdkMetadata,
788
- internalDoNotUseMetadata: {
789
- rid: 'ridForPerson',
790
- },
791
- } satisfies Person & { internalDoNotUseMetadata: { rid: string } } as Person;
792
- ",
793
- "/foo/ontology/objects/Todo.ts": "import type { PropertyDef as $PropertyDef } from '@osdk/client';
794
- import { $osdkMetadata } from '../../OntologyMetadata.js';
795
- import type { $ExpectedClientVersion } from '../../OntologyMetadata.js';
796
- import type { Person } from './Person.js';
797
- import type {
798
- PropertyKeys as $PropertyKeys,
799
- ObjectTypeDefinition as $ObjectTypeDefinition,
800
- ObjectMetadata as $ObjectMetadata,
801
- } from '@osdk/client';
802
- import type {
803
- ObjectSet as $ObjectSet,
804
- Osdk as $Osdk,
805
- OsdkObject as $OsdkObject,
806
- PropertyValueWireToClient as $PropType,
807
- SingleLinkAccessor as $SingleLinkAccessor,
808
- } from '@osdk/client';
809
-
810
- export namespace Todo {
811
- export type PropertyKeys = 'id' | 'body' | 'complete' | 'array';
812
-
813
- export interface Links {
814
- readonly Assignee: $SingleLinkAccessor<Person>;
815
- }
816
-
817
- export interface Props {
818
- /**
819
- * (no ontology metadata)
820
- */
821
- readonly array: ('a' | 'b' | 'c')[] | undefined;
822
- /**
823
- * display name: 'Body',
824
- *
825
- * description: The text of the todo
826
- */
827
- readonly body: $PropType['string'] | undefined;
828
- /**
829
- * (no ontology metadata)
830
- */
831
- readonly complete: $PropType['boolean'] | undefined;
832
- /**
833
- * (no ontology metadata)
834
- */
835
- readonly id: $PropType['integer'];
836
- }
837
- export type StrictProps = Props;
838
-
839
- export interface ObjectSet extends $ObjectSet<Todo, Todo.ObjectSet> {}
840
-
841
- export type OsdkInstance<
842
- OPTIONS extends never | '$rid' = never,
843
- K extends keyof Todo.Props = keyof Todo.Props,
844
- > = $Osdk.Instance<Todo, OPTIONS, K>;
845
-
846
- /** @deprecated use OsdkInstance */
847
- export type OsdkObject<
848
- OPTIONS extends never | '$rid' = never,
849
- K extends keyof Todo.Props = keyof Todo.Props,
850
- > = OsdkInstance<OPTIONS, K>;
851
- }
852
-
853
- export interface Todo extends $ObjectTypeDefinition {
854
- osdkMetadata: typeof $osdkMetadata;
855
- type: 'object';
856
- apiName: 'Todo';
857
- __DefinitionMetadata?: {
858
- objectSet: Todo.ObjectSet;
859
- props: Todo.Props;
860
- linksType: Todo.Links;
861
- strictProps: Todo.StrictProps;
862
- apiName: 'Todo';
863
- description: 'Its a todo item.';
864
- displayName: 'AwesomeTodoDisplayname';
865
- icon: {
866
- type: 'blueprint';
867
- name: 'document';
868
- color: 'blue';
869
- };
870
- implements: ['SomeInterface'];
871
- interfaceMap: {
872
- SomeInterface: {
873
- SomeProperty: 'body';
874
- };
875
- };
876
- inverseInterfaceMap: {
877
- SomeInterface: {
878
- body: 'SomeProperty';
879
- };
880
- };
881
- links: {
882
- Assignee: $ObjectMetadata.Link<Person, false>;
883
- };
884
- pluralDisplayName: 'AwesomeTodoDisplayNames';
885
- primaryKeyApiName: 'id';
886
- primaryKeyType: 'integer';
887
- properties: {
888
- /**
889
- * (no ontology metadata)
890
- */
891
- array: $PropertyDef<'string', 'nullable', 'array'>;
892
- /**
893
- * display name: 'Body',
894
- *
895
- * description: The text of the todo
896
- */
897
- body: $PropertyDef<'string', 'nullable', 'single'>;
898
- /**
899
- * (no ontology metadata)
900
- */
901
- complete: $PropertyDef<'boolean', 'nullable', 'single'>;
902
- /**
903
- * (no ontology metadata)
904
- */
905
- id: $PropertyDef<'integer', 'non-nullable', 'single'>;
906
- };
907
- rid: 'ridForTodo';
908
- status: 'ACTIVE';
909
- titleProperty: 'body';
910
- type: 'object';
911
- visibility: undefined;
912
- };
913
- }
914
-
915
- export const Todo = {
916
- type: 'object',
917
- apiName: 'Todo',
918
- osdkMetadata: $osdkMetadata,
919
- internalDoNotUseMetadata: {
920
- rid: 'ridForTodo',
921
- },
922
- } satisfies Todo & { internalDoNotUseMetadata: { rid: string } } as Todo;
923
- ",
924
- "/foo/ontology/queries.ts": "export { getCount } from './queries/getCount.js';
925
- export { returnsTodo } from './queries/returnsTodo.js';
926
- ",
927
- "/foo/ontology/queries/getCount.ts": "import type { ObjectSpecifier, QueryDefinition, QueryParam, QueryResult, VersionBound } from '@osdk/client';
928
- import type { $ExpectedClientVersion } from '../../OntologyMetadata.js';
929
- import { $osdkMetadata } from '../../OntologyMetadata.js';
930
-
931
- export namespace getCount {
932
- export interface Signature {
933
- (query: getCount.Parameters): Promise<getCount.ReturnType>;
934
- }
935
-
936
- export interface Parameters {
937
- /**
938
- * (no ontology metadata)
939
- */
940
- readonly completed: QueryParam.PrimitiveType<'boolean'>;
941
- }
942
-
943
- export type ReturnType = QueryResult.PrimitiveType<'integer'>;
944
- }
945
-
946
- export interface getCount extends QueryDefinition<getCount.Signature>, VersionBound<$ExpectedClientVersion> {
947
- __DefinitionMetadata?: {
948
- apiName: 'getCount';
949
- rid: 'rid.query.1';
950
- type: 'query';
951
- version: '1.1.0';
952
- isFixedVersion: false;
953
- parameters: {
954
- /**
955
- * (no ontology metadata)
956
- */
957
- completed: {
958
- nullable: false;
959
- type: 'boolean';
960
- };
961
- };
962
- output: {
963
- nullable: false;
964
- type: 'integer';
965
- };
966
- signature: getCount.Signature;
967
- };
968
- apiName: 'getCount';
969
- type: 'query';
970
- version: '1.1.0';
971
- osdkMetadata: typeof $osdkMetadata;
972
- }
973
-
974
- export const getCount: getCount = {
975
- apiName: 'getCount',
976
- type: 'query',
977
- version: '1.1.0',
978
- isFixedVersion: false,
979
- osdkMetadata: $osdkMetadata,
980
- };
981
- ",
982
- "/foo/ontology/queries/returnsTodo.ts": "import type { ObjectSpecifier, QueryDefinition, QueryParam, QueryResult, VersionBound } from '@osdk/client';
983
- import type { $ExpectedClientVersion } from '../../OntologyMetadata.js';
984
- import { $osdkMetadata } from '../../OntologyMetadata.js';
985
- import type { Todo } from '../objects/Todo.js';
986
-
987
- export namespace returnsTodo {
988
- export interface Signature {
989
- (query: returnsTodo.Parameters): Promise<returnsTodo.ReturnType>;
990
- }
991
-
992
- export interface Parameters {
993
- /**
994
- * description: Random desc so we test jsdoc
995
- */
996
- readonly someTodo: QueryParam.ObjectType<Todo>;
997
- }
998
-
999
- export type ReturnType = QueryResult.ObjectType<Todo>;
1000
- }
1001
-
1002
- export interface returnsTodo extends QueryDefinition<returnsTodo.Signature>, VersionBound<$ExpectedClientVersion> {
1003
- __DefinitionMetadata?: {
1004
- apiName: 'returnsTodo';
1005
- rid: 'rid.query.2';
1006
- type: 'query';
1007
- version: '3.2.0';
1008
- isFixedVersion: false;
1009
- parameters: {
1010
- /**
1011
- * description: Random desc so we test jsdoc
1012
- */
1013
- someTodo: {
1014
- description: 'Random desc so we test jsdoc';
1015
- nullable: false;
1016
- object: 'Todo';
1017
- type: 'object';
1018
- __OsdkTargetType?: Todo;
1019
- };
1020
- };
1021
- output: {
1022
- nullable: false;
1023
- object: 'Todo';
1024
- type: 'object';
1025
- __OsdkTargetType?: Todo;
1026
- };
1027
- signature: returnsTodo.Signature;
1028
- };
1029
- apiName: 'returnsTodo';
1030
- type: 'query';
1031
- version: '3.2.0';
1032
- osdkMetadata: typeof $osdkMetadata;
1033
- }
1034
-
1035
- export const returnsTodo: returnsTodo = {
1036
- apiName: 'returnsTodo',
1037
- type: 'query',
1038
- version: '3.2.0',
1039
- isFixedVersion: false,
1040
- osdkMetadata: $osdkMetadata,
1041
- };
1042
- ",
1043
- }
1044
- `);
1045
- });
1046
- test("throws an error when target destination is not empty", async () => {
1047
- helper.minimalFiles.readdir = vi.fn(async () => ["file"]);
1048
- await expect(async () => {
1049
- await expect(generateClientSdkVersionTwoPointZero(TodoWireOntology, "typescript-sdk/0.0.0 osdk-cli/0.0.0", helper.minimalFiles, BASE_PATH)).rejects.toThrow();
1050
- });
1051
- });
1052
- it("throws an error if a namespace is provided that all top levels do not use", async () => {
1053
- await expect(generateClientSdkVersionTwoPointZero({
1054
- ...TodoWireOntology
1055
- }, "", helper.minimalFiles, BASE_PATH, "module", undefined, undefined, undefined, true));
1056
-
1057
- // Disabled for now since we can't really enforce it from dev console at the moment
1058
- // .rejects.toThrowErrorMatchingInlineSnapshot(
1059
- // `[Error: Found type { ns:'undefined', shortName: 'Todo'} but it is not in the generation namespace 'foo.bar'. This violates the contract of the generator.]`,
1060
- // );
1061
- });
1062
- it("does not throw an error if a namespace is provided that all top levels use", async () => {
1063
- await expect(generateClientSdkVersionTwoPointZero(fooBarTodoWireOntology, "", helper.minimalFiles, BASE_PATH, "module", undefined, undefined, undefined, true)).resolves.toMatchInlineSnapshot(`undefined`);
1064
- expect(helper.getFiles()["/foo/ontology/objects/foo.bar.Todo.ts"]).toBeUndefined();
1065
- expect(helper.getFiles()["/foo/ontology/objects/Todo.ts"]).not.toBeUndefined();
1066
- expect(tweakedFilesForSnapshotConsistency(helper.getFiles())).toMatchInlineSnapshot(`
1067
- {
1068
- "/foo/OntologyMetadata.ts": "export type $ExpectedClientVersion = 'PLACEHOLDER';
1069
- export const $osdkMetadata = { extraUserAgent: '' };
1070
-
1071
- export const $ontologyRid = 'ridHere';
1072
- ",
1073
- "/foo/index.ts": "export { deleteTodos, markTodoCompleted } from './ontology/actions.js';
1074
- export * as $Actions from './ontology/actions.js';
1075
- export { SomeInterface } from './ontology/interfaces.js';
1076
- export * as $Interfaces from './ontology/interfaces.js';
1077
- export { Person, Todo } from './ontology/objects.js';
1078
- export * as $Objects from './ontology/objects.js';
1079
- export { getCount, returnsTodo } from './ontology/queries.js';
1080
- export * as $Queries from './ontology/queries.js';
1081
- export { $osdkMetadata } from './OntologyMetadata.js';
1082
- export { $ontologyRid } from './OntologyMetadata.js';
1083
- ",
1084
- "/foo/ontology/actions.ts": "export { deleteTodos } from './actions/deleteTodos.js';
1085
- export { markTodoCompleted } from './actions/markTodoCompleted.js';
1086
- ",
1087
- "/foo/ontology/actions/deleteTodos.ts": "import type {
1088
- ActionDefinition,
1089
- ActionMetadata,
1090
- ActionParam,
1091
- ActionReturnTypeForOptions,
1092
- ApplyActionOptions,
1093
- ApplyBatchActionOptions,
1094
- } from '@osdk/api';
1095
- import { $osdkMetadata } from '../../OntologyMetadata.js';
1096
- import type { Todo } from '../objects/Todo.js';
1097
-
1098
- export namespace deleteTodos {
1099
- // Represents the definition of the parameters for the action
1100
- export type ParamsDefinition = {
1101
- object: {
1102
- description: 'Todo(s) to be deleted';
1103
- multiplicity: true;
1104
- nullable: true;
1105
- type: ActionMetadata.DataType.Object<Todo>;
1106
- };
1107
- };
1108
-
1109
- /**
1110
- * An action which takes in an array of objects
1111
- */
1112
- export interface Params {
1113
- /**
1114
- * Todo(s) to be deleted
1115
- */
1116
- readonly object?: ReadonlyArray<ActionParam.ObjectType<Todo>> | null;
1117
- }
1118
-
1119
- // Represents a fqn of the action
1120
- export interface Signatures {
1121
- /**
1122
- * An action which takes in an array of objects
1123
- */
1124
- applyAction<OP extends ApplyActionOptions>(
1125
- args: deleteTodos.Params,
1126
- options?: OP,
1127
- ): Promise<ActionReturnTypeForOptions<OP>>;
1128
-
1129
- batchApplyAction<OP extends ApplyBatchActionOptions>(
1130
- args: ReadonlyArray<deleteTodos.Params>,
1131
- options?: OP,
1132
- ): Promise<ActionReturnTypeForOptions<OP>>;
1133
- }
1134
- }
1135
-
1136
- /**
1137
- * An action which takes in an array of objects
1138
- *
1139
- * **Note on null values:** _For optional parameters, explicitly providing a null value instead of undefined
1140
- * can change the behavior of the applied action. If prefills are configured, null prevents them
1141
- * from being applied. If a parameter modifies an object's property, null will clear the data from
1142
- * the object, whereas undefined would not modify that property._
1143
- * @param {ActionParam.ObjectType<Todo>} [object] Todo(s) to be deleted
1144
- */
1145
- export interface deleteTodos extends ActionDefinition<deleteTodos.Signatures> {
1146
- __DefinitionMetadata?: {
1147
- apiName: 'foo.bar.deleteTodos';
1148
- description: 'An action which takes in an array of objects';
1149
- modifiedEntities: {};
1150
- parameters: deleteTodos.ParamsDefinition;
1151
- rid: 'ri.ontology.main.action-type.8f94017d-cf17-4fa8-84c3-8e01e5d594f2';
1152
- status: 'ACTIVE';
1153
- type: 'action';
1154
-
1155
- signatures: deleteTodos.Signatures;
1156
- };
1157
- apiName: 'foo.bar.deleteTodos';
1158
- type: 'action';
1159
- osdkMetadata: typeof $osdkMetadata;
1160
- }
1161
-
1162
- export const deleteTodos: deleteTodos = {
1163
- apiName: 'foo.bar.deleteTodos',
1164
- type: 'action',
1165
- osdkMetadata: $osdkMetadata,
1166
- };
1167
- ",
1168
- "/foo/ontology/actions/markTodoCompleted.ts": "import type {
1169
- ActionDefinition,
1170
- ActionMetadata,
1171
- ActionParam,
1172
- ActionReturnTypeForOptions,
1173
- ApplyActionOptions,
1174
- ApplyBatchActionOptions,
1175
- } from '@osdk/api';
1176
- import { $osdkMetadata } from '../../OntologyMetadata.js';
1177
- import type { Todo } from '../objects/Todo.js';
1178
-
1179
- export namespace markTodoCompleted {
1180
- // Represents the definition of the parameters for the action
1181
- export type ParamsDefinition = {
1182
- object: {
1183
- description: 'A Todo to mark completed';
1184
- multiplicity: false;
1185
- nullable: true;
1186
- type: ActionMetadata.DataType.Object<Todo>;
1187
- };
1188
- };
1189
-
1190
- /**
1191
- * An action which takes different types of parameters
1192
- */
1193
- export interface Params {
1194
- /**
1195
- * A Todo to mark completed
1196
- */
1197
- readonly object?: ActionParam.ObjectType<Todo> | null;
1198
- }
1199
-
1200
- // Represents a fqn of the action
1201
- export interface Signatures {
1202
- /**
1203
- * An action which takes different types of parameters
1204
- */
1205
- applyAction<OP extends ApplyActionOptions>(
1206
- args: markTodoCompleted.Params,
1207
- options?: OP,
1208
- ): Promise<ActionReturnTypeForOptions<OP>>;
1209
-
1210
- batchApplyAction<OP extends ApplyBatchActionOptions>(
1211
- args: ReadonlyArray<markTodoCompleted.Params>,
1212
- options?: OP,
1213
- ): Promise<ActionReturnTypeForOptions<OP>>;
1214
- }
1215
- }
1216
-
1217
- /**
1218
- * An action which takes different types of parameters
1219
- *
1220
- * **Note on null values:** _For optional parameters, explicitly providing a null value instead of undefined
1221
- * can change the behavior of the applied action. If prefills are configured, null prevents them
1222
- * from being applied. If a parameter modifies an object's property, null will clear the data from
1223
- * the object, whereas undefined would not modify that property._
1224
- * @param {ActionParam.ObjectType<Todo>} [object] A Todo to mark completed
1225
- */
1226
- export interface markTodoCompleted extends ActionDefinition<markTodoCompleted.Signatures> {
1227
- __DefinitionMetadata?: {
1228
- apiName: 'foo.bar.markTodoCompleted';
1229
- description: 'An action which takes different types of parameters';
1230
- modifiedEntities: {
1231
- 'foo.bar.Todo': {
1232
- created: false;
1233
- modified: true;
1234
- };
1235
- };
1236
- parameters: markTodoCompleted.ParamsDefinition;
1237
- rid: 'ri.ontology.main.action-type.9f84017d-cf17-4fa8-84c3-8e01e5d594f2';
1238
- status: 'ACTIVE';
1239
- type: 'action';
1240
-
1241
- signatures: markTodoCompleted.Signatures;
1242
- };
1243
- apiName: 'foo.bar.markTodoCompleted';
1244
- type: 'action';
1245
- osdkMetadata: typeof $osdkMetadata;
1246
- }
1247
-
1248
- export const markTodoCompleted: markTodoCompleted = {
1249
- apiName: 'foo.bar.markTodoCompleted',
1250
- type: 'action',
1251
- osdkMetadata: $osdkMetadata,
1252
- };
1253
- ",
1254
- "/foo/ontology/interfaces.ts": "export { SomeInterface } from './interfaces/SomeInterface.js';
1255
- ",
1256
- "/foo/ontology/interfaces/SomeInterface.ts": "import type { PropertyDef as $PropertyDef } from '@osdk/api';
1257
- import { $osdkMetadata } from '../../OntologyMetadata.js';
1258
-
1259
- import type {
1260
- InterfaceDefinition as $InterfaceDefinition,
1261
- InterfaceMetadata as $InterfaceMetadata,
1262
- ObjectSet as $ObjectSet,
1263
- Osdk as $Osdk,
1264
- PropertyValueWireToClient as $PropType,
1265
- } from '@osdk/api';
1266
-
1267
- export type OsdkObjectLinks$SomeInterface = {};
1268
-
1269
- export namespace SomeInterface {
1270
- export type PropertyKeys = 'SomeProperty';
1271
-
1272
- export interface Props {
1273
- /**
1274
- * display name: 'Sum Property',
1275
- *
1276
- * description: Some property
1277
- */
1278
- readonly SomeProperty: $PropType['string'] | undefined;
1279
- }
1280
- export type StrictProps = Props;
1281
-
1282
- export interface ObjectSet extends $ObjectSet<SomeInterface, SomeInterface.ObjectSet> {}
1283
-
1284
- export type OsdkInstance<
1285
- OPTIONS extends never | '$rid' = never,
1286
- K extends keyof SomeInterface.Props = keyof SomeInterface.Props,
1287
- > = $Osdk.Instance<SomeInterface, OPTIONS, K>;
1288
-
1289
- /** @deprecated use OsdkInstance */
1290
- export type OsdkObject<
1291
- OPTIONS extends never | '$rid' = never,
1292
- K extends keyof SomeInterface.Props = keyof SomeInterface.Props,
1293
- > = OsdkInstance<OPTIONS, K>;
1294
- }
1295
-
1296
- export interface SomeInterface extends $InterfaceDefinition {
1297
- osdkMetadata: typeof $osdkMetadata;
1298
- type: 'interface';
1299
- apiName: 'foo.bar.SomeInterface';
1300
- __DefinitionMetadata?: {
1301
- objectSet: SomeInterface.ObjectSet;
1302
- props: SomeInterface.Props;
1303
- linksType: OsdkObjectLinks$SomeInterface;
1304
- strictProps: SomeInterface.StrictProps;
1305
- apiName: 'foo.bar.SomeInterface';
1306
- description: 'Some interface';
1307
- displayName: 'Sum Interface';
1308
- implementedBy: [];
1309
- implements: [];
1310
- links: {};
1311
- properties: {
1312
- /**
1313
- * display name: 'Sum Property',
1314
- *
1315
- * description: Some property
1316
- */
1317
- SomeProperty: $PropertyDef<'string', 'nullable', 'single'>;
1318
- };
1319
- rid: 'idk';
1320
- type: 'interface';
1321
- };
1322
- }
1323
-
1324
- export const SomeInterface = {
1325
- type: 'interface',
1326
- apiName: 'foo.bar.SomeInterface',
1327
- osdkMetadata: $osdkMetadata,
1328
- internalDoNotUseMetadata: {
1329
- rid: 'idk',
1330
- },
1331
- } satisfies SomeInterface & { internalDoNotUseMetadata: { rid: string } } as SomeInterface;
1332
- ",
1333
- "/foo/ontology/objects.ts": "export { Person } from './objects/Person.js';
1334
- export { Todo } from './objects/Todo.js';
1335
- ",
1336
- "/foo/ontology/objects/Person.ts": "import type { PropertyDef as $PropertyDef } from '@osdk/api';
1337
- import { $osdkMetadata } from '../../OntologyMetadata.js';
1338
- import type { $ExpectedClientVersion } from '../../OntologyMetadata.js';
1339
- import type { Todo } from './Todo.js';
1340
- import type {
1341
- PropertyKeys as $PropertyKeys,
1342
- ObjectTypeDefinition as $ObjectTypeDefinition,
1343
- ObjectMetadata as $ObjectMetadata,
1344
- } from '@osdk/api';
1345
- import type {
1346
- ObjectSet as $ObjectSet,
1347
- Osdk as $Osdk,
1348
- OsdkObject as $OsdkObject,
1349
- PropertyValueWireToClient as $PropType,
1350
- SingleLinkAccessor as $SingleLinkAccessor,
1351
- } from '@osdk/api';
1352
-
1353
- export namespace Person {
1354
- export type PropertyKeys = 'email';
1355
-
1356
- export interface Links {
1357
- readonly Todos: Todo.ObjectSet;
1358
- }
1359
-
1360
- export interface Props {
1361
- /**
1362
- * (no ontology metadata)
1363
- */
1364
- readonly email: 'osdk@palantir.com' | 'foundry@palantir.com';
1365
- }
1366
- export type StrictProps = Props;
1367
-
1368
- export interface ObjectSet extends $ObjectSet<Person, Person.ObjectSet> {}
1369
-
1370
- export type OsdkInstance<
1371
- OPTIONS extends never | '$rid' = never,
1372
- K extends keyof Person.Props = keyof Person.Props,
1373
- > = $Osdk.Instance<Person, OPTIONS, K>;
1374
-
1375
- /** @deprecated use OsdkInstance */
1376
- export type OsdkObject<
1377
- OPTIONS extends never | '$rid' = never,
1378
- K extends keyof Person.Props = keyof Person.Props,
1379
- > = OsdkInstance<OPTIONS, K>;
1380
- }
1381
-
1382
- export interface Person extends $ObjectTypeDefinition {
1383
- osdkMetadata: typeof $osdkMetadata;
1384
- type: 'object';
1385
- apiName: 'foo.bar.Person';
1386
- __DefinitionMetadata?: {
1387
- objectSet: Person.ObjectSet;
1388
- props: Person.Props;
1389
- linksType: Person.Links;
1390
- strictProps: Person.StrictProps;
1391
- apiName: 'foo.bar.Person';
1392
- description: 'A person';
1393
- displayName: 'Person';
1394
- icon: {
1395
- type: 'blueprint';
1396
- name: 'document';
1397
- color: 'blue';
1398
- };
1399
- implements: [];
1400
- interfaceMap: {};
1401
- inverseInterfaceMap: {};
1402
- links: {
1403
- Todos: $ObjectMetadata.Link<Todo, true>;
1404
- };
1405
- pluralDisplayName: 'Persons';
1406
- primaryKeyApiName: 'email';
1407
- primaryKeyType: 'string';
1408
- properties: {
1409
- /**
1410
- * (no ontology metadata)
1411
- */
1412
- email: $PropertyDef<'string', 'non-nullable', 'single'>;
1413
- };
1414
- rid: 'ridForPerson';
1415
- status: 'ACTIVE';
1416
- titleProperty: 'email';
1417
- type: 'object';
1418
- visibility: undefined;
1419
- };
1420
- }
1421
-
1422
- export const Person = {
1423
- type: 'object',
1424
- apiName: 'foo.bar.Person',
1425
- osdkMetadata: $osdkMetadata,
1426
- internalDoNotUseMetadata: {
1427
- rid: 'ridForPerson',
1428
- },
1429
- } satisfies Person & { internalDoNotUseMetadata: { rid: string } } as Person;
1430
- ",
1431
- "/foo/ontology/objects/Todo.ts": "import type { PropertyDef as $PropertyDef } from '@osdk/api';
1432
- import { $osdkMetadata } from '../../OntologyMetadata.js';
1433
- import type { $ExpectedClientVersion } from '../../OntologyMetadata.js';
1434
- import type { Person } from './Person.js';
1435
- import type {
1436
- PropertyKeys as $PropertyKeys,
1437
- ObjectTypeDefinition as $ObjectTypeDefinition,
1438
- ObjectMetadata as $ObjectMetadata,
1439
- } from '@osdk/api';
1440
- import type {
1441
- ObjectSet as $ObjectSet,
1442
- Osdk as $Osdk,
1443
- OsdkObject as $OsdkObject,
1444
- PropertyValueWireToClient as $PropType,
1445
- SingleLinkAccessor as $SingleLinkAccessor,
1446
- } from '@osdk/api';
1447
-
1448
- export namespace Todo {
1449
- export type PropertyKeys = 'id' | 'body' | 'complete' | 'array';
1450
-
1451
- export interface Links {
1452
- readonly Assignee: $SingleLinkAccessor<Person>;
1453
- }
1454
-
1455
- export interface Props {
1456
- /**
1457
- * (no ontology metadata)
1458
- */
1459
- readonly array: ('a' | 'b' | 'c')[] | undefined;
1460
- /**
1461
- * display name: 'Body',
1462
- *
1463
- * description: The text of the todo
1464
- */
1465
- readonly body: $PropType['string'] | undefined;
1466
- /**
1467
- * (no ontology metadata)
1468
- */
1469
- readonly complete: $PropType['boolean'] | undefined;
1470
- /**
1471
- * (no ontology metadata)
1472
- */
1473
- readonly id: $PropType['integer'];
1474
- }
1475
- export type StrictProps = Props;
1476
-
1477
- export interface ObjectSet extends $ObjectSet<Todo, Todo.ObjectSet> {}
1478
-
1479
- export type OsdkInstance<
1480
- OPTIONS extends never | '$rid' = never,
1481
- K extends keyof Todo.Props = keyof Todo.Props,
1482
- > = $Osdk.Instance<Todo, OPTIONS, K>;
1483
-
1484
- /** @deprecated use OsdkInstance */
1485
- export type OsdkObject<
1486
- OPTIONS extends never | '$rid' = never,
1487
- K extends keyof Todo.Props = keyof Todo.Props,
1488
- > = OsdkInstance<OPTIONS, K>;
1489
- }
1490
-
1491
- export interface Todo extends $ObjectTypeDefinition {
1492
- osdkMetadata: typeof $osdkMetadata;
1493
- type: 'object';
1494
- apiName: 'foo.bar.Todo';
1495
- __DefinitionMetadata?: {
1496
- objectSet: Todo.ObjectSet;
1497
- props: Todo.Props;
1498
- linksType: Todo.Links;
1499
- strictProps: Todo.StrictProps;
1500
- apiName: 'foo.bar.Todo';
1501
- description: 'Its a todo item.';
1502
- displayName: 'AwesomeTodoDisplayname';
1503
- icon: {
1504
- type: 'blueprint';
1505
- name: 'document';
1506
- color: 'blue';
1507
- };
1508
- implements: ['foo.bar.SomeInterface'];
1509
- interfaceMap: {
1510
- 'foo.bar.SomeInterface': {
1511
- SomeProperty: 'body';
1512
- };
1513
- };
1514
- inverseInterfaceMap: {
1515
- 'foo.bar.SomeInterface': {
1516
- body: 'SomeProperty';
1517
- };
1518
- };
1519
- links: {
1520
- Assignee: $ObjectMetadata.Link<Person, false>;
1521
- };
1522
- pluralDisplayName: 'AwesomeTodoDisplayNames';
1523
- primaryKeyApiName: 'id';
1524
- primaryKeyType: 'integer';
1525
- properties: {
1526
- /**
1527
- * (no ontology metadata)
1528
- */
1529
- array: $PropertyDef<'string', 'nullable', 'array'>;
1530
- /**
1531
- * display name: 'Body',
1532
- *
1533
- * description: The text of the todo
1534
- */
1535
- body: $PropertyDef<'string', 'nullable', 'single'>;
1536
- /**
1537
- * (no ontology metadata)
1538
- */
1539
- complete: $PropertyDef<'boolean', 'nullable', 'single'>;
1540
- /**
1541
- * (no ontology metadata)
1542
- */
1543
- id: $PropertyDef<'integer', 'non-nullable', 'single'>;
1544
- };
1545
- rid: 'ridForTodo';
1546
- status: 'ACTIVE';
1547
- titleProperty: 'body';
1548
- type: 'object';
1549
- visibility: undefined;
1550
- };
1551
- }
1552
-
1553
- export const Todo = {
1554
- type: 'object',
1555
- apiName: 'foo.bar.Todo',
1556
- osdkMetadata: $osdkMetadata,
1557
- internalDoNotUseMetadata: {
1558
- rid: 'ridForTodo',
1559
- },
1560
- } satisfies Todo & { internalDoNotUseMetadata: { rid: string } } as Todo;
1561
- ",
1562
- "/foo/ontology/queries.ts": "export { getCount } from './queries/getCount.js';
1563
- export { returnsTodo } from './queries/returnsTodo.js';
1564
- ",
1565
- "/foo/ontology/queries/getCount.ts": "import type { ObjectSpecifier, QueryDefinition, QueryParam, QueryResult, VersionBound } from '@osdk/api';
1566
- import type { $ExpectedClientVersion } from '../../OntologyMetadata.js';
1567
- import { $osdkMetadata } from '../../OntologyMetadata.js';
1568
-
1569
- export namespace getCount {
1570
- export interface Signature {
1571
- (query: getCount.Parameters): Promise<getCount.ReturnType>;
1572
- }
1573
-
1574
- export interface Parameters {
1575
- /**
1576
- * (no ontology metadata)
1577
- */
1578
- readonly completed: QueryParam.PrimitiveType<'boolean'>;
1579
- }
1580
-
1581
- export type ReturnType = QueryResult.PrimitiveType<'integer'>;
1582
- }
1583
-
1584
- export interface getCount extends QueryDefinition<getCount.Signature>, VersionBound<$ExpectedClientVersion> {
1585
- __DefinitionMetadata?: {
1586
- apiName: 'foo.bar.getCount';
1587
- rid: 'rid.query.1';
1588
- type: 'query';
1589
- version: '1.1.0';
1590
- isFixedVersion: false;
1591
- parameters: {
1592
- /**
1593
- * (no ontology metadata)
1594
- */
1595
- completed: {
1596
- nullable: false;
1597
- type: 'boolean';
1598
- };
1599
- };
1600
- output: {
1601
- nullable: false;
1602
- type: 'integer';
1603
- };
1604
- signature: getCount.Signature;
1605
- };
1606
- apiName: 'foo.bar.getCount';
1607
- type: 'query';
1608
- version: '1.1.0';
1609
- osdkMetadata: typeof $osdkMetadata;
1610
- }
1611
-
1612
- export const getCount: getCount = {
1613
- apiName: 'foo.bar.getCount',
1614
- type: 'query',
1615
- version: '1.1.0',
1616
- isFixedVersion: false,
1617
- osdkMetadata: $osdkMetadata,
1618
- };
1619
- ",
1620
- "/foo/ontology/queries/returnsTodo.ts": "import type { ObjectSpecifier, QueryDefinition, QueryParam, QueryResult, VersionBound } from '@osdk/api';
1621
- import type { $ExpectedClientVersion } from '../../OntologyMetadata.js';
1622
- import { $osdkMetadata } from '../../OntologyMetadata.js';
1623
- import type { Todo } from '../objects/Todo.js';
1624
-
1625
- export namespace returnsTodo {
1626
- export interface Signature {
1627
- (query: returnsTodo.Parameters): Promise<returnsTodo.ReturnType>;
1628
- }
1629
-
1630
- export interface Parameters {
1631
- /**
1632
- * description: Random desc so we test jsdoc
1633
- */
1634
- readonly someTodo: QueryParam.ObjectType<Todo>;
1635
- }
1636
-
1637
- export type ReturnType = QueryResult.ObjectType<Todo>;
1638
- }
1639
-
1640
- export interface returnsTodo extends QueryDefinition<returnsTodo.Signature>, VersionBound<$ExpectedClientVersion> {
1641
- __DefinitionMetadata?: {
1642
- apiName: 'foo.bar.returnsTodo';
1643
- rid: 'rid.query.2';
1644
- type: 'query';
1645
- version: '3.2.0';
1646
- isFixedVersion: false;
1647
- parameters: {
1648
- /**
1649
- * description: Random desc so we test jsdoc
1650
- */
1651
- someTodo: {
1652
- description: 'Random desc so we test jsdoc';
1653
- nullable: false;
1654
- object: 'foo.bar.Todo';
1655
- type: 'object';
1656
- __OsdkTargetType?: Todo;
1657
- };
1658
- };
1659
- output: {
1660
- nullable: false;
1661
- object: 'foo.bar.Todo';
1662
- type: 'object';
1663
- __OsdkTargetType?: Todo;
1664
- };
1665
- signature: returnsTodo.Signature;
1666
- };
1667
- apiName: 'foo.bar.returnsTodo';
1668
- type: 'query';
1669
- version: '3.2.0';
1670
- osdkMetadata: typeof $osdkMetadata;
1671
- }
1672
-
1673
- export const returnsTodo: returnsTodo = {
1674
- apiName: 'foo.bar.returnsTodo',
1675
- type: 'query',
1676
- version: '3.2.0',
1677
- isFixedVersion: false,
1678
- osdkMetadata: $osdkMetadata,
1679
- };
1680
- ",
1681
- }
1682
- `);
1683
- });
1684
- it("guards against empty objects", async () => {
1685
- await generateClientSdkVersionTwoPointZero({
1686
- ontology: TodoWireOntology.ontology,
1687
- actionTypes: {},
1688
- interfaceTypes: {},
1689
- objectTypes: {},
1690
- queryTypes: {},
1691
- sharedPropertyTypes: {},
1692
- valueTypes: {}
1693
- }, "", helper.minimalFiles, BASE_PATH);
1694
- expect(helper.getFiles()[`${BASE_PATH}/ontology/objects.ts`]).toEqual("export {};\n");
1695
- });
1696
- test.skip("runs generator locally", async () => {
1697
- try {
1698
- await rmdir(`${__dirname}/generated`, {
1699
- recursive: true
1700
- });
1701
- } catch (e) {}
1702
- await mkdir(`${__dirname}/generated`, {
1703
- recursive: true
1704
- });
1705
- await generateClientSdkVersionTwoPointZero(TodoWireOntology, "typescript-sdk/0.0.0 osdk-cli/0.0.0", {
1706
- writeFile: async (path, contents) => {
1707
- await writeFile(path, contents, {
1708
- flag: "w"
1709
- });
1710
- },
1711
- mkdir: async (path, options) => {
1712
- await mkdir(path, options);
1713
- },
1714
- readdir: async path => await readdir(path)
1715
- }, `${__dirname}/generated/`);
1716
- });
1717
- describe("$ontologyRid", () => {
1718
- it("does not exist when an ontology api name is provided", async () => {
1719
- await expect(generateClientSdkVersionTwoPointZero(fooBarTodoWireOntology, "", helper.minimalFiles, "/foo", "module", new Map())).resolves.toMatchInlineSnapshot(`undefined`);
1720
-
1721
- // expect(helper.getFiles()["/foo/index.ts"]).not.toContain(
1722
- // "$ontologyRid",
1723
- // );
1724
- });
1725
- it("does exist when an ontology api name is not provided", async () => {
1726
- await expect(generateClientSdkVersionTwoPointZero(TodoWireOntology, "", helper.minimalFiles, "/foo", "module", undefined, new Map())).resolves.toMatchInlineSnapshot(`undefined`);
1727
- expect(helper.getFiles()["/foo/index.ts"]).toContain("$ontologyRid");
1728
- });
1729
- });
1730
- describe("query depends on foreign object", () => {
1731
- it("generates the correct code", async () => {
1732
- await expect(generateClientSdkVersionTwoPointZero(referencingOntology, "", helper.minimalFiles, BASE_PATH, "module", new Map([["com.example.dep.Task", "@com.example.dep/osdk"]]), new Map([["com.example.dep.SomeInterface", "@com.example.dep/osdk"]]), new Map([["com.example.dep.spt", "@com.example.dep/osdk"]]), true)).resolves.toMatchInlineSnapshot(`undefined`);
1733
- expect(helper.getFiles()["/foo/ontology/queries/getTask.ts"]).toMatchInlineSnapshot(`
1734
- "import type { ObjectSpecifier, QueryDefinition, QueryParam, QueryResult, VersionBound } from '@osdk/api';
1735
- import type { $ExpectedClientVersion } from '../../OntologyMetadata.js';
1736
- import { $osdkMetadata } from '../../OntologyMetadata.js';
1737
- import type { Task as $Imported$com$example$dep$Task } from '@com.example.dep/osdk';
1738
-
1739
- export namespace getTask {
1740
- export interface Signature {
1741
- (query: getTask.Parameters): Promise<getTask.ReturnType>;
1742
- }
1743
-
1744
- export interface Parameters {
1745
- /**
1746
- * (no ontology metadata)
1747
- */
1748
- readonly a: QueryParam.ObjectType<$Imported$com$example$dep$Task>;
1749
- }
1750
-
1751
- export type ReturnType = QueryResult.ObjectType<$Imported$com$example$dep$Task>;
1752
- }
1753
-
1754
- export interface getTask extends QueryDefinition<getTask.Signature>, VersionBound<$ExpectedClientVersion> {
1755
- __DefinitionMetadata?: {
1756
- apiName: 'getTask';
1757
- rid: 'ri.a.b.c';
1758
- type: 'query';
1759
- version: '0';
1760
- isFixedVersion: false;
1761
- parameters: {
1762
- /**
1763
- * (no ontology metadata)
1764
- */
1765
- a: {
1766
- nullable: false;
1767
- object: 'com.example.dep.Task';
1768
- type: 'object';
1769
- __OsdkTargetType?: $Imported$com$example$dep$Task;
1770
- };
1771
- };
1772
- output: {
1773
- nullable: false;
1774
- object: 'com.example.dep.Task';
1775
- type: 'object';
1776
- __OsdkTargetType?: $Imported$com$example$dep$Task;
1777
- };
1778
- signature: getTask.Signature;
1779
- };
1780
- apiName: 'getTask';
1781
- type: 'query';
1782
- version: '0';
1783
- osdkMetadata: typeof $osdkMetadata;
1784
- }
1785
-
1786
- export const getTask: getTask = {
1787
- apiName: 'getTask',
1788
- type: 'query',
1789
- version: '0',
1790
- isFixedVersion: false,
1791
- osdkMetadata: $osdkMetadata,
1792
- };
1793
- "
1794
- `);
1795
- });
1796
- });
1797
- describe("object uses on foreign spt", () => {
1798
- it("stuff", async () => {
1799
- await expect(generateClientSdkVersionTwoPointZero(referencingOntology, "", helper.minimalFiles, BASE_PATH, "module", new Map([["com.example.dep.Task", "@com.example.dep/osdk"]]), new Map([["com.example.dep.SomeInterface", "@com.example.dep/osdk"]]), new Map([["com.example.dep.spt", "@com.example.dep/osdk"]]), true)).resolves.toMatchInlineSnapshot(`undefined`);
1800
- expect(helper.getFiles()["/foo/ontology/objects/UsesForeignSpt.ts"]).toMatchInlineSnapshot(`
1801
- "import type { PropertyDef as $PropertyDef } from '@osdk/api';
1802
- import { $osdkMetadata } from '../../OntologyMetadata.js';
1803
- import type { $ExpectedClientVersion } from '../../OntologyMetadata.js';
1804
- import type {
1805
- PropertyKeys as $PropertyKeys,
1806
- ObjectTypeDefinition as $ObjectTypeDefinition,
1807
- ObjectMetadata as $ObjectMetadata,
1808
- } from '@osdk/api';
1809
- import type {
1810
- ObjectSet as $ObjectSet,
1811
- Osdk as $Osdk,
1812
- OsdkObject as $OsdkObject,
1813
- PropertyValueWireToClient as $PropType,
1814
- SingleLinkAccessor as $SingleLinkAccessor,
1815
- } from '@osdk/api';
1816
-
1817
- export namespace UsesForeignSpt {
1818
- export type PropertyKeys = 'id' | 'body';
1819
-
1820
- export type Links = {};
1821
-
1822
- export interface Props {
1823
- /**
1824
- * (no ontology metadata)
1825
- */
1826
- readonly body: $PropType['string'] | undefined;
1827
- /**
1828
- * (no ontology metadata)
1829
- */
1830
- readonly id: $PropType['integer'];
1831
- }
1832
- export type StrictProps = Props;
1833
-
1834
- export interface ObjectSet extends $ObjectSet<UsesForeignSpt, UsesForeignSpt.ObjectSet> {}
1835
-
1836
- export type OsdkInstance<
1837
- OPTIONS extends never | '$rid' = never,
1838
- K extends keyof UsesForeignSpt.Props = keyof UsesForeignSpt.Props,
1839
- > = $Osdk.Instance<UsesForeignSpt, OPTIONS, K>;
1840
-
1841
- /** @deprecated use OsdkInstance */
1842
- export type OsdkObject<
1843
- OPTIONS extends never | '$rid' = never,
1844
- K extends keyof UsesForeignSpt.Props = keyof UsesForeignSpt.Props,
1845
- > = OsdkInstance<OPTIONS, K>;
1846
- }
1847
-
1848
- export interface UsesForeignSpt extends $ObjectTypeDefinition {
1849
- osdkMetadata: typeof $osdkMetadata;
1850
- type: 'object';
1851
- apiName: 'UsesForeignSpt';
1852
- __DefinitionMetadata?: {
1853
- objectSet: UsesForeignSpt.ObjectSet;
1854
- props: UsesForeignSpt.Props;
1855
- linksType: UsesForeignSpt.Links;
1856
- strictProps: UsesForeignSpt.StrictProps;
1857
- apiName: 'UsesForeignSpt';
1858
- description: undefined;
1859
- displayName: 'Uses Foreign Spt';
1860
- icon: {
1861
- type: 'blueprint';
1862
- color: 'blue';
1863
- name: 'document';
1864
- };
1865
- implements: [];
1866
- interfaceMap: {};
1867
- inverseInterfaceMap: {};
1868
- links: {};
1869
- pluralDisplayName: 'Uses Foreign Spts';
1870
- primaryKeyApiName: 'id';
1871
- primaryKeyType: 'integer';
1872
- properties: {
1873
- /**
1874
- * (no ontology metadata)
1875
- */
1876
- body: $PropertyDef<'string', 'nullable', 'single'>;
1877
- /**
1878
- * (no ontology metadata)
1879
- */
1880
- id: $PropertyDef<'integer', 'non-nullable', 'single'>;
1881
- };
1882
- rid: 'theRid';
1883
- status: 'ACTIVE';
1884
- titleProperty: 'id';
1885
- type: 'object';
1886
- visibility: undefined;
1887
- };
1888
- }
1889
-
1890
- export const UsesForeignSpt = {
1891
- type: 'object',
1892
- apiName: 'UsesForeignSpt',
1893
- osdkMetadata: $osdkMetadata,
1894
- internalDoNotUseMetadata: {
1895
- rid: 'theRid',
1896
- },
1897
- } satisfies UsesForeignSpt & { internalDoNotUseMetadata: { rid: string } } as UsesForeignSpt;
1898
- "
1899
- `);
1900
- });
1901
- });
1902
- describe("action depends on foreign object", () => {
1903
- it("can generate the action", async () => {
1904
- await expect(generateClientSdkVersionTwoPointZero(referencingOntology, "", helper.minimalFiles, BASE_PATH, "module", new Map([["com.example.dep.Task", "@com.example.dep/osdk"]]), new Map([["com.example.dep.SomeInterface", "@com.example.dep/osdk"]]), new Map([["com.example.dep.spt", "@com.example.dep/osdk"]]), true)).resolves.toMatchInlineSnapshot(`undefined`);
1905
- expect(helper.getFiles()["/foo/ontology/actions/setTaskBody.ts"]).toMatchInlineSnapshot(`
1906
- "import type {
1907
- ActionDefinition,
1908
- ActionMetadata,
1909
- ActionParam,
1910
- ActionReturnTypeForOptions,
1911
- ApplyActionOptions,
1912
- ApplyBatchActionOptions,
1913
- } from '@osdk/api';
1914
- import { $osdkMetadata } from '../../OntologyMetadata.js';
1915
- import type { Task as $Imported$com$example$dep$Task } from '@com.example.dep/osdk';
1916
-
1917
- export namespace setTaskBody {
1918
- // Represents the definition of the parameters for the action
1919
- export type ParamsDefinition = {
1920
- body: {
1921
- description: undefined;
1922
- multiplicity: false;
1923
- nullable: false;
1924
- type: 'string';
1925
- };
1926
- task: {
1927
- description: undefined;
1928
- multiplicity: false;
1929
- nullable: false;
1930
- type: ActionMetadata.DataType.Object<$Imported$com$example$dep$Task>;
1931
- };
1932
- };
1933
-
1934
- export interface Params {
1935
- readonly body: ActionParam.PrimitiveType<'string'>;
1936
-
1937
- readonly task: ActionParam.ObjectType<$Imported$com$example$dep$Task>;
1938
- }
1939
-
1940
- // Represents a fqn of the action
1941
- export interface Signatures {
1942
- applyAction<OP extends ApplyActionOptions>(
1943
- args: setTaskBody.Params,
1944
- options?: OP,
1945
- ): Promise<ActionReturnTypeForOptions<OP>>;
1946
-
1947
- batchApplyAction<OP extends ApplyBatchActionOptions>(
1948
- args: ReadonlyArray<setTaskBody.Params>,
1949
- options?: OP,
1950
- ): Promise<ActionReturnTypeForOptions<OP>>;
1951
- }
1952
- }
1953
-
1954
- /**
1955
- * @param {ActionParam.PrimitiveType<"string">} body
1956
- * @param {ActionParam.ObjectType<$Imported$com$example$dep$Task>} task
1957
- */
1958
- export interface setTaskBody extends ActionDefinition<setTaskBody.Signatures> {
1959
- __DefinitionMetadata?: {
1960
- apiName: 'setTaskBody';
1961
- modifiedEntities: {
1962
- 'com.example.dep.Task': {
1963
- created: false;
1964
- modified: true;
1965
- };
1966
- };
1967
- parameters: setTaskBody.ParamsDefinition;
1968
- rid: 'ri.a.b.c.d';
1969
- status: 'ACTIVE';
1970
- type: 'action';
1971
-
1972
- signatures: setTaskBody.Signatures;
1973
- };
1974
- apiName: 'setTaskBody';
1975
- type: 'action';
1976
- osdkMetadata: typeof $osdkMetadata;
1977
- }
1978
-
1979
- export const setTaskBody: setTaskBody = {
1980
- apiName: 'setTaskBody',
1981
- type: 'action',
1982
- osdkMetadata: $osdkMetadata,
1983
- };
1984
- "
1985
- `);
1986
- });
1987
- });
1988
- describe("queries with versions", () => {
1989
- it("can generate properly when queries have versions and optionally have fixed versions", async () => {
1990
- await generateClientSdkVersionTwoPointZero({
1991
- ontology: TodoWireOntology.ontology,
1992
- actionTypes: {},
1993
- interfaceTypes: {},
1994
- objectTypes: TodoWireOntology.objectTypes,
1995
- queryTypes: {
1996
- "getCount:1.1.0": {
1997
- ...TodoWireOntology.queryTypes.getCount
1998
- },
1999
- "returnsTodo:3.2.0": {
2000
- ...TodoWireOntology.queryTypes.returnsTodo,
2001
- version: "0"
2002
- }
2003
- },
2004
- sharedPropertyTypes: {},
2005
- valueTypes: {}
2006
- }, "typescript-sdk/0.0.0 osdk-cli/0.0.0", helper.minimalFiles, BASE_PATH, "module", new Map(), new Map(), new Map(), false, ["getCount"]);
2007
- expect(tweakedFilesForSnapshotConsistency(helper.getFiles())).toMatchInlineSnapshot(`
2008
- {
2009
- "/foo/OntologyMetadata.ts": "export type $ExpectedClientVersion = 'PLACEHOLDER';
2010
- export const $osdkMetadata = { extraUserAgent: 'typescript-sdk/0.0.0 osdk-cli/0.0.0' };
2011
-
2012
- export const $ontologyRid = 'ridHere';
2013
- ",
2014
- "/foo/index.ts": "export {} from './ontology/actions.js';
2015
- export * as $Actions from './ontology/actions.js';
2016
- export {} from './ontology/interfaces.js';
2017
- export * as $Interfaces from './ontology/interfaces.js';
2018
- export { Person, Todo } from './ontology/objects.js';
2019
- export * as $Objects from './ontology/objects.js';
2020
- export { getCount, returnsTodo } from './ontology/queries.js';
2021
- export * as $Queries from './ontology/queries.js';
2022
- export { $osdkMetadata } from './OntologyMetadata.js';
2023
- export { $ontologyRid } from './OntologyMetadata.js';
2024
- ",
2025
- "/foo/ontology/actions.ts": "export {};
2026
- ",
2027
- "/foo/ontology/interfaces.ts": "export {};
2028
- ",
2029
- "/foo/ontology/objects.ts": "export { Person } from './objects/Person.js';
2030
- export { Todo } from './objects/Todo.js';
2031
- ",
2032
- "/foo/ontology/objects/Person.ts": "import type { PropertyDef as $PropertyDef } from '@osdk/client';
2033
- import { $osdkMetadata } from '../../OntologyMetadata.js';
2034
- import type { $ExpectedClientVersion } from '../../OntologyMetadata.js';
2035
- import type { Todo } from './Todo.js';
2036
- import type {
2037
- PropertyKeys as $PropertyKeys,
2038
- ObjectTypeDefinition as $ObjectTypeDefinition,
2039
- ObjectMetadata as $ObjectMetadata,
2040
- } from '@osdk/client';
2041
- import type {
2042
- ObjectSet as $ObjectSet,
2043
- Osdk as $Osdk,
2044
- OsdkObject as $OsdkObject,
2045
- PropertyValueWireToClient as $PropType,
2046
- SingleLinkAccessor as $SingleLinkAccessor,
2047
- } from '@osdk/client';
2048
-
2049
- export namespace Person {
2050
- export type PropertyKeys = 'email';
2051
-
2052
- export interface Links {
2053
- readonly Todos: Todo.ObjectSet;
2054
- }
2055
-
2056
- export interface Props {
2057
- /**
2058
- * (no ontology metadata)
2059
- */
2060
- readonly email: $PropType['string'];
2061
- }
2062
- export type StrictProps = Props;
2063
-
2064
- export interface ObjectSet extends $ObjectSet<Person, Person.ObjectSet> {}
2065
-
2066
- export type OsdkInstance<
2067
- OPTIONS extends never | '$rid' = never,
2068
- K extends keyof Person.Props = keyof Person.Props,
2069
- > = $Osdk.Instance<Person, OPTIONS, K>;
2070
-
2071
- /** @deprecated use OsdkInstance */
2072
- export type OsdkObject<
2073
- OPTIONS extends never | '$rid' = never,
2074
- K extends keyof Person.Props = keyof Person.Props,
2075
- > = OsdkInstance<OPTIONS, K>;
2076
- }
2077
-
2078
- export interface Person extends $ObjectTypeDefinition {
2079
- osdkMetadata: typeof $osdkMetadata;
2080
- type: 'object';
2081
- apiName: 'Person';
2082
- __DefinitionMetadata?: {
2083
- objectSet: Person.ObjectSet;
2084
- props: Person.Props;
2085
- linksType: Person.Links;
2086
- strictProps: Person.StrictProps;
2087
- apiName: 'Person';
2088
- description: 'A person';
2089
- displayName: 'Person';
2090
- icon: {
2091
- type: 'blueprint';
2092
- name: 'document';
2093
- color: 'blue';
2094
- };
2095
- implements: [];
2096
- interfaceMap: {};
2097
- inverseInterfaceMap: {};
2098
- links: {
2099
- Todos: $ObjectMetadata.Link<Todo, true>;
2100
- };
2101
- pluralDisplayName: 'Persons';
2102
- primaryKeyApiName: 'email';
2103
- primaryKeyType: 'string';
2104
- properties: {
2105
- /**
2106
- * (no ontology metadata)
2107
- */
2108
- email: $PropertyDef<'string', 'non-nullable', 'single'>;
2109
- };
2110
- rid: 'ridForPerson';
2111
- status: 'ACTIVE';
2112
- titleProperty: 'email';
2113
- type: 'object';
2114
- visibility: undefined;
2115
- };
2116
- }
2117
-
2118
- export const Person = {
2119
- type: 'object',
2120
- apiName: 'Person',
2121
- osdkMetadata: $osdkMetadata,
2122
- internalDoNotUseMetadata: {
2123
- rid: 'ridForPerson',
2124
- },
2125
- } satisfies Person & { internalDoNotUseMetadata: { rid: string } } as Person;
2126
- ",
2127
- "/foo/ontology/objects/Todo.ts": "import type { PropertyDef as $PropertyDef } from '@osdk/client';
2128
- import { $osdkMetadata } from '../../OntologyMetadata.js';
2129
- import type { $ExpectedClientVersion } from '../../OntologyMetadata.js';
2130
- import type { Person } from './Person.js';
2131
- import type {
2132
- PropertyKeys as $PropertyKeys,
2133
- ObjectTypeDefinition as $ObjectTypeDefinition,
2134
- ObjectMetadata as $ObjectMetadata,
2135
- } from '@osdk/client';
2136
- import type {
2137
- ObjectSet as $ObjectSet,
2138
- Osdk as $Osdk,
2139
- OsdkObject as $OsdkObject,
2140
- PropertyValueWireToClient as $PropType,
2141
- SingleLinkAccessor as $SingleLinkAccessor,
2142
- } from '@osdk/client';
2143
-
2144
- export namespace Todo {
2145
- export type PropertyKeys = 'id' | 'body' | 'complete' | 'array';
2146
-
2147
- export interface Links {
2148
- readonly Assignee: $SingleLinkAccessor<Person>;
2149
- }
2150
-
2151
- export interface Props {
2152
- /**
2153
- * (no ontology metadata)
2154
- */
2155
- readonly array: $PropType['string'][] | undefined;
2156
- /**
2157
- * display name: 'Body',
2158
- *
2159
- * description: The text of the todo
2160
- */
2161
- readonly body: $PropType['string'] | undefined;
2162
- /**
2163
- * (no ontology metadata)
2164
- */
2165
- readonly complete: $PropType['boolean'] | undefined;
2166
- /**
2167
- * (no ontology metadata)
2168
- */
2169
- readonly id: $PropType['integer'];
2170
- }
2171
- export type StrictProps = Props;
2172
-
2173
- export interface ObjectSet extends $ObjectSet<Todo, Todo.ObjectSet> {}
2174
-
2175
- export type OsdkInstance<
2176
- OPTIONS extends never | '$rid' = never,
2177
- K extends keyof Todo.Props = keyof Todo.Props,
2178
- > = $Osdk.Instance<Todo, OPTIONS, K>;
2179
-
2180
- /** @deprecated use OsdkInstance */
2181
- export type OsdkObject<
2182
- OPTIONS extends never | '$rid' = never,
2183
- K extends keyof Todo.Props = keyof Todo.Props,
2184
- > = OsdkInstance<OPTIONS, K>;
2185
- }
2186
-
2187
- export interface Todo extends $ObjectTypeDefinition {
2188
- osdkMetadata: typeof $osdkMetadata;
2189
- type: 'object';
2190
- apiName: 'Todo';
2191
- __DefinitionMetadata?: {
2192
- objectSet: Todo.ObjectSet;
2193
- props: Todo.Props;
2194
- linksType: Todo.Links;
2195
- strictProps: Todo.StrictProps;
2196
- apiName: 'Todo';
2197
- description: 'Its a todo item.';
2198
- displayName: 'AwesomeTodoDisplayname';
2199
- icon: {
2200
- type: 'blueprint';
2201
- name: 'document';
2202
- color: 'blue';
2203
- };
2204
- implements: ['SomeInterface'];
2205
- interfaceMap: {
2206
- SomeInterface: {
2207
- SomeProperty: 'body';
2208
- };
2209
- };
2210
- inverseInterfaceMap: {
2211
- SomeInterface: {
2212
- body: 'SomeProperty';
2213
- };
2214
- };
2215
- links: {
2216
- Assignee: $ObjectMetadata.Link<Person, false>;
2217
- };
2218
- pluralDisplayName: 'AwesomeTodoDisplayNames';
2219
- primaryKeyApiName: 'id';
2220
- primaryKeyType: 'integer';
2221
- properties: {
2222
- /**
2223
- * (no ontology metadata)
2224
- */
2225
- array: $PropertyDef<'string', 'nullable', 'array'>;
2226
- /**
2227
- * display name: 'Body',
2228
- *
2229
- * description: The text of the todo
2230
- */
2231
- body: $PropertyDef<'string', 'nullable', 'single'>;
2232
- /**
2233
- * (no ontology metadata)
2234
- */
2235
- complete: $PropertyDef<'boolean', 'nullable', 'single'>;
2236
- /**
2237
- * (no ontology metadata)
2238
- */
2239
- id: $PropertyDef<'integer', 'non-nullable', 'single'>;
2240
- };
2241
- rid: 'ridForTodo';
2242
- status: 'ACTIVE';
2243
- titleProperty: 'body';
2244
- type: 'object';
2245
- visibility: undefined;
2246
- };
2247
- }
2248
-
2249
- export const Todo = {
2250
- type: 'object',
2251
- apiName: 'Todo',
2252
- osdkMetadata: $osdkMetadata,
2253
- internalDoNotUseMetadata: {
2254
- rid: 'ridForTodo',
2255
- },
2256
- } satisfies Todo & { internalDoNotUseMetadata: { rid: string } } as Todo;
2257
- ",
2258
- "/foo/ontology/queries.ts": "export { getCount } from './queries/getCount.js';
2259
- export { returnsTodo } from './queries/returnsTodo.js';
2260
- ",
2261
- "/foo/ontology/queries/getCount.ts": "import type { ObjectSpecifier, QueryDefinition, QueryParam, QueryResult, VersionBound } from '@osdk/client';
2262
- import type { $ExpectedClientVersion } from '../../OntologyMetadata.js';
2263
- import { $osdkMetadata } from '../../OntologyMetadata.js';
2264
-
2265
- export namespace getCount {
2266
- export interface Signature {
2267
- (query: getCount.Parameters): Promise<getCount.ReturnType>;
2268
- }
2269
-
2270
- export interface Parameters {
2271
- /**
2272
- * (no ontology metadata)
2273
- */
2274
- readonly completed: QueryParam.PrimitiveType<'boolean'>;
2275
- }
2276
-
2277
- export type ReturnType = QueryResult.PrimitiveType<'integer'>;
2278
- }
2279
-
2280
- export interface getCount extends QueryDefinition<getCount.Signature>, VersionBound<$ExpectedClientVersion> {
2281
- __DefinitionMetadata?: {
2282
- apiName: 'getCount';
2283
- rid: 'rid.query.1';
2284
- type: 'query';
2285
- version: '1.1.0';
2286
- isFixedVersion: true;
2287
- parameters: {
2288
- /**
2289
- * (no ontology metadata)
2290
- */
2291
- completed: {
2292
- nullable: false;
2293
- type: 'boolean';
2294
- };
2295
- };
2296
- output: {
2297
- nullable: false;
2298
- type: 'integer';
2299
- };
2300
- signature: getCount.Signature;
2301
- };
2302
- apiName: 'getCount';
2303
- type: 'query';
2304
- version: '1.1.0';
2305
- osdkMetadata: typeof $osdkMetadata;
2306
- }
2307
-
2308
- export const getCount: getCount = {
2309
- apiName: 'getCount',
2310
- type: 'query',
2311
- version: '1.1.0',
2312
- isFixedVersion: true,
2313
- osdkMetadata: $osdkMetadata,
2314
- };
2315
- ",
2316
- "/foo/ontology/queries/returnsTodo.ts": "import type { ObjectSpecifier, QueryDefinition, QueryParam, QueryResult, VersionBound } from '@osdk/client';
2317
- import type { $ExpectedClientVersion } from '../../OntologyMetadata.js';
2318
- import { $osdkMetadata } from '../../OntologyMetadata.js';
2319
- import type { Todo } from '../objects/Todo.js';
2320
-
2321
- export namespace returnsTodo {
2322
- export interface Signature {
2323
- (query: returnsTodo.Parameters): Promise<returnsTodo.ReturnType>;
2324
- }
2325
-
2326
- export interface Parameters {
2327
- /**
2328
- * description: Random desc so we test jsdoc
2329
- */
2330
- readonly someTodo: QueryParam.ObjectType<Todo>;
2331
- }
2332
-
2333
- export type ReturnType = QueryResult.ObjectType<Todo>;
2334
- }
2335
-
2336
- export interface returnsTodo extends QueryDefinition<returnsTodo.Signature>, VersionBound<$ExpectedClientVersion> {
2337
- __DefinitionMetadata?: {
2338
- apiName: 'returnsTodo';
2339
- rid: 'rid.query.2';
2340
- type: 'query';
2341
- version: '0';
2342
- isFixedVersion: false;
2343
- parameters: {
2344
- /**
2345
- * description: Random desc so we test jsdoc
2346
- */
2347
- someTodo: {
2348
- description: 'Random desc so we test jsdoc';
2349
- nullable: false;
2350
- object: 'Todo';
2351
- type: 'object';
2352
- __OsdkTargetType?: Todo;
2353
- };
2354
- };
2355
- output: {
2356
- nullable: false;
2357
- object: 'Todo';
2358
- type: 'object';
2359
- __OsdkTargetType?: Todo;
2360
- };
2361
- signature: returnsTodo.Signature;
2362
- };
2363
- apiName: 'returnsTodo';
2364
- type: 'query';
2365
- version: '0';
2366
- osdkMetadata: typeof $osdkMetadata;
2367
- }
2368
-
2369
- export const returnsTodo: returnsTodo = {
2370
- apiName: 'returnsTodo',
2371
- type: 'query',
2372
- version: '0',
2373
- isFixedVersion: false,
2374
- osdkMetadata: $osdkMetadata,
2375
- };
2376
- ",
2377
- }
2378
- `);
2379
- });
2380
- });
2381
- it("can generate an sdk package that is entirely a library", async () => {
2382
- const mockConsola = vi.spyOn(consola, "info");
2383
- await expect(generateClientSdkVersionTwoPointZero(referencedOntology, "", helper.minimalFiles, BASE_PATH, "module")).resolves.toMatchInlineSnapshot(`undefined`);
2384
- expect(mockConsola).toHaveBeenCalledWith(`{"type":"futureUnknownType"} is not a supported propertyType`);
2385
- expect(tweakedFilesForSnapshotConsistency(helper.getFiles())).toMatchInlineSnapshot(`
2386
- {
2387
- "/foo/OntologyMetadata.ts": "export type $ExpectedClientVersion = 'PLACEHOLDER';
2388
- export const $osdkMetadata = { extraUserAgent: '' };
2389
-
2390
- export const $ontologyRid = 'ri.ontology.main.ontology.dep';
2391
-
2392
- export const $branch = 'someRidHere';
2393
- ",
2394
- "/foo/index.ts": "export {} from './ontology/actions.js';
2395
- export * as $Actions from './ontology/actions.js';
2396
- export { SomeInterface } from './ontology/interfaces.js';
2397
- export * as $Interfaces from './ontology/interfaces.js';
2398
- export { Task } from './ontology/objects.js';
2399
- export * as $Objects from './ontology/objects.js';
2400
- export {} from './ontology/queries.js';
2401
- export * as $Queries from './ontology/queries.js';
2402
- export { $osdkMetadata } from './OntologyMetadata.js';
2403
- export { $ontologyRid } from './OntologyMetadata.js';
2404
- ",
2405
- "/foo/ontology/actions.ts": "export {};
2406
- ",
2407
- "/foo/ontology/interfaces.ts": "export { SomeInterface } from './interfaces/SomeInterface.js';
2408
- ",
2409
- "/foo/ontology/interfaces/SomeInterface.ts": "import type { PropertyDef as $PropertyDef } from '@osdk/client';
2410
- import { $osdkMetadata } from '../../OntologyMetadata.js';
2411
-
2412
- import type {
2413
- InterfaceDefinition as $InterfaceDefinition,
2414
- InterfaceMetadata as $InterfaceMetadata,
2415
- ObjectSet as $ObjectSet,
2416
- Osdk as $Osdk,
2417
- PropertyValueWireToClient as $PropType,
2418
- } from '@osdk/client';
2419
-
2420
- export type OsdkObjectLinks$SomeInterface = {};
2421
-
2422
- export namespace SomeInterface {
2423
- export type PropertyKeys = 'spt' | 'spt2';
2424
-
2425
- export interface Props {
2426
- /**
2427
- * display name: 'Some Property'
2428
- */
2429
- readonly spt: $PropType['string'] | undefined;
2430
- /**
2431
- * display name: 'Some Property 2'
2432
- */
2433
- readonly spt2: $PropType['string'] | undefined;
2434
- }
2435
- export type StrictProps = Props;
2436
-
2437
- export interface ObjectSet extends $ObjectSet<SomeInterface, SomeInterface.ObjectSet> {}
2438
-
2439
- export type OsdkInstance<
2440
- OPTIONS extends never | '$rid' = never,
2441
- K extends keyof SomeInterface.Props = keyof SomeInterface.Props,
2442
- > = $Osdk.Instance<SomeInterface, OPTIONS, K>;
2443
-
2444
- /** @deprecated use OsdkInstance */
2445
- export type OsdkObject<
2446
- OPTIONS extends never | '$rid' = never,
2447
- K extends keyof SomeInterface.Props = keyof SomeInterface.Props,
2448
- > = OsdkInstance<OPTIONS, K>;
2449
- }
2450
-
2451
- export interface SomeInterface extends $InterfaceDefinition {
2452
- osdkMetadata: typeof $osdkMetadata;
2453
- type: 'interface';
2454
- apiName: 'com.example.dep.SomeInterface';
2455
- __DefinitionMetadata?: {
2456
- objectSet: SomeInterface.ObjectSet;
2457
- props: SomeInterface.Props;
2458
- linksType: OsdkObjectLinks$SomeInterface;
2459
- strictProps: SomeInterface.StrictProps;
2460
- apiName: 'com.example.dep.SomeInterface';
2461
- description: undefined;
2462
- displayName: 'Sum Interface';
2463
- implementedBy: [];
2464
- implements: [];
2465
- links: {};
2466
- properties: {
2467
- /**
2468
- * display name: 'Some Property'
2469
- */
2470
- spt: $PropertyDef<'string', 'nullable', 'single'>;
2471
- /**
2472
- * display name: 'Some Property 2'
2473
- */
2474
- spt2: $PropertyDef<'string', 'nullable', 'single'>;
2475
- };
2476
- rid: 'idk2';
2477
- type: 'interface';
2478
- };
2479
- }
2480
-
2481
- export const SomeInterface = {
2482
- type: 'interface',
2483
- apiName: 'com.example.dep.SomeInterface',
2484
- osdkMetadata: $osdkMetadata,
2485
- internalDoNotUseMetadata: {
2486
- rid: 'idk2',
2487
- },
2488
- } satisfies SomeInterface & { internalDoNotUseMetadata: { rid: string } } as SomeInterface;
2489
- ",
2490
- "/foo/ontology/objects.ts": "export { Task } from './objects/Task.js';
2491
- ",
2492
- "/foo/ontology/objects/Task.ts": "import type { PropertyDef as $PropertyDef } from '@osdk/client';
2493
- import { $osdkMetadata } from '../../OntologyMetadata.js';
2494
- import type { $ExpectedClientVersion } from '../../OntologyMetadata.js';
2495
- import type {
2496
- PropertyKeys as $PropertyKeys,
2497
- ObjectTypeDefinition as $ObjectTypeDefinition,
2498
- ObjectMetadata as $ObjectMetadata,
2499
- } from '@osdk/client';
2500
- import type {
2501
- ObjectSet as $ObjectSet,
2502
- Osdk as $Osdk,
2503
- OsdkObject as $OsdkObject,
2504
- PropertyValueWireToClient as $PropType,
2505
- SingleLinkAccessor as $SingleLinkAccessor,
2506
- } from '@osdk/client';
2507
-
2508
- export namespace Task {
2509
- export type PropertyKeys = 'taskId' | 'body';
2510
-
2511
- export type Links = {};
2512
-
2513
- export interface Props {
2514
- /**
2515
- * (no ontology metadata)
2516
- */
2517
- readonly body: $PropType['string'] | undefined;
2518
- /**
2519
- * (no ontology metadata)
2520
- */
2521
- readonly taskId: $PropType['string'];
2522
- }
2523
- export type StrictProps = Props;
2524
-
2525
- export interface ObjectSet extends $ObjectSet<Task, Task.ObjectSet> {}
2526
-
2527
- export type OsdkInstance<
2528
- OPTIONS extends never | '$rid' = never,
2529
- K extends keyof Task.Props = keyof Task.Props,
2530
- > = $Osdk.Instance<Task, OPTIONS, K>;
2531
-
2532
- /** @deprecated use OsdkInstance */
2533
- export type OsdkObject<
2534
- OPTIONS extends never | '$rid' = never,
2535
- K extends keyof Task.Props = keyof Task.Props,
2536
- > = OsdkInstance<OPTIONS, K>;
2537
- }
2538
-
2539
- export interface Task extends $ObjectTypeDefinition {
2540
- osdkMetadata: typeof $osdkMetadata;
2541
- type: 'object';
2542
- apiName: 'com.example.dep.Task';
2543
- __DefinitionMetadata?: {
2544
- objectSet: Task.ObjectSet;
2545
- props: Task.Props;
2546
- linksType: Task.Links;
2547
- strictProps: Task.StrictProps;
2548
- apiName: 'com.example.dep.Task';
2549
- description: undefined;
2550
- displayName: 'Task';
2551
- icon: {
2552
- type: 'blueprint';
2553
- color: 'blue';
2554
- name: 'document';
2555
- };
2556
- implements: [];
2557
- interfaceMap: {};
2558
- inverseInterfaceMap: {};
2559
- links: {};
2560
- pluralDisplayName: 'Tasks';
2561
- primaryKeyApiName: 'taskId';
2562
- primaryKeyType: 'string';
2563
- properties: {
2564
- /**
2565
- * (no ontology metadata)
2566
- */
2567
- body: $PropertyDef<'string', 'nullable', 'single'>;
2568
- /**
2569
- * (no ontology metadata)
2570
- */
2571
- taskId: $PropertyDef<'string', 'non-nullable', 'single'>;
2572
- };
2573
- rid: 'ridForTask';
2574
- status: 'ACTIVE';
2575
- titleProperty: 'taskId';
2576
- type: 'object';
2577
- visibility: undefined;
2578
- };
2579
- }
2580
-
2581
- export const Task = {
2582
- type: 'object',
2583
- apiName: 'com.example.dep.Task',
2584
- osdkMetadata: $osdkMetadata,
2585
- internalDoNotUseMetadata: {
2586
- rid: 'ridForTask',
2587
- },
2588
- } satisfies Task & { internalDoNotUseMetadata: { rid: string } } as Task;
2589
- ",
2590
- "/foo/ontology/queries.ts": "export {};
2591
- ",
2592
- }
2593
- `);
2594
- });
2595
- });
2596
- function tweakedFilesForSnapshotConsistency(files) {
2597
- const ret = {
2598
- ...files
2599
- };
2600
- ret["/foo/OntologyMetadata.ts"] = ret["/foo/OntologyMetadata.ts"].replace(/export type \$ExpectedClientVersion = '.*?';/, `export type $ExpectedClientVersion = 'PLACEHOLDER';`);
2601
- return ret;
2602
- }
2603
- //# sourceMappingURL=generateClientSdkVersionTwoPointZero.test.js.map