@party-stack/salesforce-ontology 0.4.0 → 0.4.2

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 (166) hide show
  1. package/README.md +22 -31
  2. package/lib/actionMetadata.d.ts +11 -9
  3. package/lib/actionMetadata.d.ts.map +1 -1
  4. package/lib/actionMetadata.js +19 -30
  5. package/lib/actionMetadata.js.map +1 -1
  6. package/lib/adapter/convertLoadSubsetOptions.d.ts +10 -8
  7. package/lib/adapter/convertLoadSubsetOptions.d.ts.map +1 -1
  8. package/lib/adapter/convertLoadSubsetOptions.js +110 -173
  9. package/lib/adapter/convertLoadSubsetOptions.js.map +1 -1
  10. package/lib/adapter/createSalesforceOntologyBackendAdapter.d.ts +14 -12
  11. package/lib/adapter/createSalesforceOntologyBackendAdapter.d.ts.map +1 -1
  12. package/lib/adapter/createSalesforceOntologyBackendAdapter.js +124 -191
  13. package/lib/adapter/createSalesforceOntologyBackendAdapter.js.map +1 -1
  14. package/lib/adapter/index.d.ts +5 -5
  15. package/lib/adapter/index.js +5 -5
  16. package/lib/adapter/objectCollectionOptions.d.ts +22 -22
  17. package/lib/adapter/objectCollectionOptions.d.ts.map +1 -1
  18. package/lib/adapter/objectCollectionOptions.js +198 -280
  19. package/lib/adapter/objectCollectionOptions.js.map +1 -1
  20. package/lib/adapter/salesforceCodec.d.ts +6 -4
  21. package/lib/adapter/salesforceCodec.d.ts.map +1 -1
  22. package/lib/adapter/salesforceCodec.js +126 -190
  23. package/lib/adapter/salesforceCodec.js.map +1 -1
  24. package/lib/config/index.d.ts +20 -18
  25. package/lib/config/index.d.ts.map +1 -1
  26. package/lib/config/index.js +148 -192
  27. package/lib/config/index.js.map +1 -1
  28. package/lib/connection.d.ts +35 -33
  29. package/lib/connection.d.ts.map +1 -1
  30. package/lib/connection.js +243 -299
  31. package/lib/connection.js.map +1 -1
  32. package/lib/crud.d.ts +5 -3
  33. package/lib/crud.d.ts.map +1 -1
  34. package/lib/crud.js +0 -1
  35. package/lib/index.d.ts +10 -5
  36. package/lib/index.js +10 -5
  37. package/lib/installation/createSalesforceBackendInstallation.d.ts +28 -26
  38. package/lib/installation/createSalesforceBackendInstallation.d.ts.map +1 -1
  39. package/lib/installation/createSalesforceBackendInstallation.js +75 -85
  40. package/lib/installation/createSalesforceBackendInstallation.js.map +1 -1
  41. package/lib/installation/index.d.ts +2 -2
  42. package/lib/installation/index.js +1 -2
  43. package/lib/meta/actionTypeCollectionOptions.d.ts +10 -8
  44. package/lib/meta/actionTypeCollectionOptions.d.ts.map +1 -1
  45. package/lib/meta/actionTypeCollectionOptions.js +105 -212
  46. package/lib/meta/actionTypeCollectionOptions.js.map +1 -1
  47. package/lib/meta/convertMetaActionType.d.ts +4 -2
  48. package/lib/meta/convertMetaActionType.d.ts.map +1 -1
  49. package/lib/meta/convertMetaActionType.js +32 -32
  50. package/lib/meta/convertMetaActionType.js.map +1 -1
  51. package/lib/meta/convertMetaLinkType.d.ts +4 -2
  52. package/lib/meta/convertMetaLinkType.d.ts.map +1 -1
  53. package/lib/meta/convertMetaLinkType.js +39 -45
  54. package/lib/meta/convertMetaLinkType.js.map +1 -1
  55. package/lib/meta/convertMetaLoadSubsetOptions.d.ts +12 -10
  56. package/lib/meta/convertMetaLoadSubsetOptions.d.ts.map +1 -1
  57. package/lib/meta/convertMetaLoadSubsetOptions.js +42 -58
  58. package/lib/meta/convertMetaLoadSubsetOptions.js.map +1 -1
  59. package/lib/meta/convertMetaObjectType.d.ts +4 -2
  60. package/lib/meta/convertMetaObjectType.d.ts.map +1 -1
  61. package/lib/meta/convertMetaObjectType.js +36 -40
  62. package/lib/meta/convertMetaObjectType.js.map +1 -1
  63. package/lib/meta/convertMetaQueryFunctionType.d.ts +4 -2
  64. package/lib/meta/convertMetaQueryFunctionType.d.ts.map +1 -1
  65. package/lib/meta/convertMetaQueryFunctionType.js +27 -25
  66. package/lib/meta/convertMetaQueryFunctionType.js.map +1 -1
  67. package/lib/meta/convertMetaTypeDef.d.ts +10 -8
  68. package/lib/meta/convertMetaTypeDef.d.ts.map +1 -1
  69. package/lib/meta/convertMetaTypeDef.js +196 -188
  70. package/lib/meta/convertMetaTypeDef.js.map +1 -1
  71. package/lib/meta/createSalesforceMetaOntologyBackendAdapter.d.ts +19 -17
  72. package/lib/meta/createSalesforceMetaOntologyBackendAdapter.d.ts.map +1 -1
  73. package/lib/meta/createSalesforceMetaOntologyBackendAdapter.js +38 -40
  74. package/lib/meta/createSalesforceMetaOntologyBackendAdapter.js.map +1 -1
  75. package/lib/meta/entityCollectionOptions.d.ts +10 -8
  76. package/lib/meta/entityCollectionOptions.d.ts.map +1 -1
  77. package/lib/meta/entityCollectionOptions.js +73 -82
  78. package/lib/meta/entityCollectionOptions.js.map +1 -1
  79. package/lib/meta/index.d.ts +7 -7
  80. package/lib/meta/index.js +7 -7
  81. package/lib/meta/queryFunctionTypeCollectionOptions.d.ts +7 -5
  82. package/lib/meta/queryFunctionTypeCollectionOptions.d.ts.map +1 -1
  83. package/lib/meta/queryFunctionTypeCollectionOptions.js +53 -91
  84. package/lib/meta/queryFunctionTypeCollectionOptions.js.map +1 -1
  85. package/lib/meta/synthesizeCrudActionTypes.d.ts +4 -2
  86. package/lib/meta/synthesizeCrudActionTypes.d.ts.map +1 -1
  87. package/lib/meta/synthesizeCrudActionTypes.js +77 -116
  88. package/lib/meta/synthesizeCrudActionTypes.js.map +1 -1
  89. package/lib/standardActions.d.ts +2 -0
  90. package/lib/standardActions.d.ts.map +1 -1
  91. package/lib/standardActions.js +22 -20
  92. package/lib/standardActions.js.map +1 -1
  93. package/lib/utils/AsyncIterable.d.ts +2 -0
  94. package/lib/utils/AsyncIterable.d.ts.map +1 -1
  95. package/lib/utils/AsyncIterable.js +20 -23
  96. package/lib/utils/AsyncIterable.js.map +1 -1
  97. package/lib/utils/ids.d.ts +2 -0
  98. package/lib/utils/ids.d.ts.map +1 -1
  99. package/lib/utils/ids.js +23 -19
  100. package/lib/utils/ids.js.map +1 -1
  101. package/package.json +18 -24
  102. package/lib/adapter/convertLoadSubsetOptions.test.d.ts +0 -2
  103. package/lib/adapter/convertLoadSubsetOptions.test.d.ts.map +0 -1
  104. package/lib/adapter/convertLoadSubsetOptions.test.js +0 -80
  105. package/lib/adapter/convertLoadSubsetOptions.test.js.map +0 -1
  106. package/lib/adapter/createSalesforceOntologyBackendAdapter.test.d.ts +0 -2
  107. package/lib/adapter/createSalesforceOntologyBackendAdapter.test.d.ts.map +0 -1
  108. package/lib/adapter/createSalesforceOntologyBackendAdapter.test.js +0 -394
  109. package/lib/adapter/createSalesforceOntologyBackendAdapter.test.js.map +0 -1
  110. package/lib/adapter/index.d.ts.map +0 -1
  111. package/lib/adapter/index.js.map +0 -1
  112. package/lib/adapter/objectCollectionOptions.test.d.ts +0 -2
  113. package/lib/adapter/objectCollectionOptions.test.d.ts.map +0 -1
  114. package/lib/adapter/objectCollectionOptions.test.js +0 -160
  115. package/lib/adapter/objectCollectionOptions.test.js.map +0 -1
  116. package/lib/adapter/salesforceCodec.test.d.ts +0 -2
  117. package/lib/adapter/salesforceCodec.test.d.ts.map +0 -1
  118. package/lib/adapter/salesforceCodec.test.js +0 -57
  119. package/lib/adapter/salesforceCodec.test.js.map +0 -1
  120. package/lib/config/index.test.d.ts +0 -2
  121. package/lib/config/index.test.d.ts.map +0 -1
  122. package/lib/config/index.test.js +0 -177
  123. package/lib/config/index.test.js.map +0 -1
  124. package/lib/connection.test.d.ts +0 -2
  125. package/lib/connection.test.d.ts.map +0 -1
  126. package/lib/connection.test.js +0 -189
  127. package/lib/connection.test.js.map +0 -1
  128. package/lib/crud.js.map +0 -1
  129. package/lib/index.d.ts.map +0 -1
  130. package/lib/index.js.map +0 -1
  131. package/lib/installation/createSalesforceBackendInstallation.test.d.ts +0 -2
  132. package/lib/installation/createSalesforceBackendInstallation.test.d.ts.map +0 -1
  133. package/lib/installation/createSalesforceBackendInstallation.test.js +0 -55
  134. package/lib/installation/createSalesforceBackendInstallation.test.js.map +0 -1
  135. package/lib/installation/index.d.ts.map +0 -1
  136. package/lib/installation/index.js.map +0 -1
  137. package/lib/meta/actionTypeCollectionOptions.test.d.ts +0 -2
  138. package/lib/meta/actionTypeCollectionOptions.test.d.ts.map +0 -1
  139. package/lib/meta/actionTypeCollectionOptions.test.js +0 -192
  140. package/lib/meta/actionTypeCollectionOptions.test.js.map +0 -1
  141. package/lib/meta/convertMetaActionType.test.d.ts +0 -2
  142. package/lib/meta/convertMetaActionType.test.d.ts.map +0 -1
  143. package/lib/meta/convertMetaActionType.test.js +0 -185
  144. package/lib/meta/convertMetaActionType.test.js.map +0 -1
  145. package/lib/meta/convertMetaObjectType.test.d.ts +0 -2
  146. package/lib/meta/convertMetaObjectType.test.d.ts.map +0 -1
  147. package/lib/meta/convertMetaObjectType.test.js +0 -187
  148. package/lib/meta/convertMetaObjectType.test.js.map +0 -1
  149. package/lib/meta/convertMetaQueryFunctionType.test.d.ts +0 -2
  150. package/lib/meta/convertMetaQueryFunctionType.test.d.ts.map +0 -1
  151. package/lib/meta/convertMetaQueryFunctionType.test.js +0 -58
  152. package/lib/meta/convertMetaQueryFunctionType.test.js.map +0 -1
  153. package/lib/meta/entityCollectionOptions.test.d.ts +0 -2
  154. package/lib/meta/entityCollectionOptions.test.d.ts.map +0 -1
  155. package/lib/meta/entityCollectionOptions.test.js +0 -120
  156. package/lib/meta/entityCollectionOptions.test.js.map +0 -1
  157. package/lib/meta/index.d.ts.map +0 -1
  158. package/lib/meta/index.js.map +0 -1
  159. package/lib/meta/queryFunctionTypeCollectionOptions.test.d.ts +0 -2
  160. package/lib/meta/queryFunctionTypeCollectionOptions.test.d.ts.map +0 -1
  161. package/lib/meta/queryFunctionTypeCollectionOptions.test.js +0 -71
  162. package/lib/meta/queryFunctionTypeCollectionOptions.test.js.map +0 -1
  163. package/lib/meta/synthesizeCrudActionTypes.test.d.ts +0 -2
  164. package/lib/meta/synthesizeCrudActionTypes.test.d.ts.map +0 -1
  165. package/lib/meta/synthesizeCrudActionTypes.test.js +0 -153
  166. package/lib/meta/synthesizeCrudActionTypes.test.js.map +0 -1
@@ -1,201 +1,137 @@
1
1
  import { Temporal } from "temporal-polyfill";
2
+ //#region src/adapter/salesforceCodec.ts
2
3
  function isPlainObject(value) {
3
- return typeof value === "object" && value !== null && !Array.isArray(value);
4
+ return typeof value === "object" && value !== null && !Array.isArray(value);
4
5
  }
5
6
  function stripAttributes(object) {
6
- const { attributes, ...rest } = object;
7
- void attributes;
8
- return rest;
7
+ const { attributes, ...rest } = object;
8
+ return rest;
9
9
  }
10
- export function createSalesforceCodec(ir) {
11
- const objectTypes = new Map(ir.objectTypes.map((objectType) => [objectType.name, objectType]));
12
- const namedTypes = new Map(ir.types.map((type) => [type.name, type.type]));
13
- const resolveType = (type, seen = new Set()) => {
14
- if (type.kind !== "ref") {
15
- return type;
16
- }
17
- const name = type.value.name;
18
- if (seen.has(name)) {
19
- throw new Error(`Circular ontology type reference "${name}".`);
20
- }
21
- const resolved = namedTypes.get(name);
22
- if (!resolved) {
23
- throw new Error(`Unknown ontology type reference "${name}".`);
24
- }
25
- return resolveType(resolved, new Set([...seen, name]));
26
- };
27
- const decodeValue = (type, value) => {
28
- const resolvedType = resolveType(type);
29
- if (value === undefined || value === null) {
30
- if (resolvedType.kind === "optional") {
31
- return undefined;
32
- }
33
- return value;
34
- }
35
- switch (resolvedType.kind) {
36
- case "string":
37
- return value;
38
- case "boolean":
39
- return typeof value === "string" ? value === "true" : value;
40
- case "integer":
41
- case "float":
42
- case "double":
43
- return typeof value === "string" ? Number(value) : value;
44
- case "date":
45
- return typeof value === "string" ? Temporal.PlainDate.from(value) : value;
46
- case "timestamp":
47
- if (typeof value === "string") {
48
- // Salesforce datetime wire format is typically ISO-8601.
49
- return Temporal.Instant.from(value.endsWith("Z") || value.includes("+") ? value : `${value}Z`);
50
- }
51
- if (typeof value === "number")
52
- return Temporal.Instant.fromEpochMilliseconds(value);
53
- return value;
54
- case "geopoint":
55
- return decodeGeoPoint(value);
56
- case "objectReference":
57
- return value;
58
- case "list":
59
- if (typeof value === "string") {
60
- // Multipicklist values are semicolon-delimited.
61
- return value
62
- .split(";")
63
- .filter((entry) => entry.length > 0)
64
- .map((item) => decodeValue(resolvedType.value.elementType, item));
65
- }
66
- return Array.isArray(value)
67
- ? value.map((item) => decodeValue(resolvedType.value.elementType, item))
68
- : value;
69
- case "map":
70
- if (!isPlainObject(value)) {
71
- return value;
72
- }
73
- return Object.fromEntries(Object.entries(value).map(([key, entryValue]) => [
74
- decodeValue(resolvedType.value.keyType, key),
75
- decodeValue(resolvedType.value.valueType, entryValue),
76
- ]));
77
- case "struct":
78
- if (!isPlainObject(value)) {
79
- return value;
80
- }
81
- return Object.fromEntries(Object.entries(stripAttributes(value)).map(([key, entryValue]) => {
82
- const field = resolvedType.value.fields.find((candidate) => candidate.name === key);
83
- return [key, field ? decodeValue(field.type, entryValue) : entryValue];
84
- }));
85
- case "optional":
86
- return decodeValue(resolvedType.value.type, value);
87
- case "attachment":
88
- case "union":
89
- case "result":
90
- case "unknown":
91
- return value;
92
- case "ref":
93
- return decodeValue(resolveType(resolvedType), value);
94
- }
95
- };
96
- const encodeValue = (type, value) => {
97
- const resolvedType = resolveType(type);
98
- if (value === undefined || value === null) {
99
- return null;
100
- }
101
- switch (resolvedType.kind) {
102
- case "string":
103
- case "boolean":
104
- case "integer":
105
- case "float":
106
- case "double":
107
- case "objectReference":
108
- case "unknown":
109
- return value;
110
- case "date":
111
- if (value instanceof Temporal.PlainDate)
112
- return value.toString();
113
- if (value instanceof Date)
114
- return value.toISOString().slice(0, 10);
115
- return value;
116
- case "timestamp":
117
- if (value instanceof Temporal.Instant)
118
- return value.toString();
119
- if (value instanceof Date)
120
- return value.toISOString();
121
- return value;
122
- case "geopoint":
123
- return encodeGeoPoint(value);
124
- case "list":
125
- if (!Array.isArray(value))
126
- return value;
127
- // Multipicklist wire format uses semicolon delimiters for string lists.
128
- if (resolvedType.value.elementType.kind === "string") {
129
- return value
130
- .map((item) => encodeValue(resolvedType.value.elementType, item))
131
- .filter((item) => {
132
- return (typeof item === "string" ||
133
- typeof item === "number" ||
134
- typeof item === "boolean");
135
- })
136
- .join(";");
137
- }
138
- return value.map((item) => encodeValue(resolvedType.value.elementType, item));
139
- case "map":
140
- if (!isPlainObject(value))
141
- return value;
142
- return Object.fromEntries(Object.entries(value).map(([key, entryValue]) => [
143
- encodeValue(resolvedType.value.keyType, key),
144
- encodeValue(resolvedType.value.valueType, entryValue),
145
- ]));
146
- case "struct":
147
- if (!isPlainObject(value))
148
- return value;
149
- return Object.fromEntries(Object.entries(value).map(([key, entryValue]) => {
150
- const field = resolvedType.value.fields.find((candidate) => candidate.name === key);
151
- return [key, field ? encodeValue(field.type, entryValue) : entryValue];
152
- }));
153
- case "optional":
154
- return encodeValue(resolvedType.value.type, value);
155
- case "attachment":
156
- case "union":
157
- case "result":
158
- return value;
159
- case "ref":
160
- return encodeValue(resolveType(resolvedType), value);
161
- }
162
- };
163
- const decodeObjectType = (objectType, object) => {
164
- const cleaned = stripAttributes(object);
165
- return Object.fromEntries(objectType.properties.map((property) => [
166
- property.name,
167
- decodeValue(property.type, cleaned[property.name]),
168
- ]));
169
- };
170
- return {
171
- decodeObject: (objectTypeName, object) => {
172
- const objectType = objectTypes.get(objectTypeName);
173
- if (!objectType) {
174
- throw new Error(`Unknown object type "${objectTypeName}".`);
175
- }
176
- return decodeObjectType(objectType, object);
177
- },
178
- decodeValue,
179
- encodeValue,
180
- };
10
+ function createSalesforceCodec(ir) {
11
+ const objectTypes = new Map(ir.objectTypes.map((objectType) => [objectType.name, objectType]));
12
+ const namedTypes = new Map(ir.types.map((type) => [type.name, type.type]));
13
+ const resolveType = (type, seen = /* @__PURE__ */ new Set()) => {
14
+ if (type.kind !== "ref") return type;
15
+ const name = type.value.name;
16
+ if (seen.has(name)) throw new Error(`Circular ontology type reference "${name}".`);
17
+ const resolved = namedTypes.get(name);
18
+ if (!resolved) throw new Error(`Unknown ontology type reference "${name}".`);
19
+ return resolveType(resolved, /* @__PURE__ */ new Set([...seen, name]));
20
+ };
21
+ const decodeValue = (type, value) => {
22
+ const resolvedType = resolveType(type);
23
+ if (value === void 0 || value === null) {
24
+ if (resolvedType.kind === "optional") return;
25
+ return value;
26
+ }
27
+ switch (resolvedType.kind) {
28
+ case "string": return value;
29
+ case "boolean": return typeof value === "string" ? value === "true" : value;
30
+ case "integer":
31
+ case "float":
32
+ case "double": return typeof value === "string" ? Number(value) : value;
33
+ case "date": return typeof value === "string" ? Temporal.PlainDate.from(value) : value;
34
+ case "timestamp":
35
+ if (typeof value === "string") return Temporal.Instant.from(value.endsWith("Z") || value.includes("+") ? value : `${value}Z`);
36
+ if (typeof value === "number") return Temporal.Instant.fromEpochMilliseconds(value);
37
+ return value;
38
+ case "geopoint": return decodeGeoPoint(value);
39
+ case "objectReference": return value;
40
+ case "list":
41
+ if (typeof value === "string") return value.split(";").filter((entry) => entry.length > 0).map((item) => decodeValue(resolvedType.value.elementType, item));
42
+ return Array.isArray(value) ? value.map((item) => decodeValue(resolvedType.value.elementType, item)) : value;
43
+ case "map":
44
+ if (!isPlainObject(value)) return value;
45
+ return Object.fromEntries(Object.entries(value).map(([key, entryValue]) => [decodeValue(resolvedType.value.keyType, key), decodeValue(resolvedType.value.valueType, entryValue)]));
46
+ case "struct":
47
+ if (!isPlainObject(value)) return value;
48
+ return Object.fromEntries(Object.entries(stripAttributes(value)).map(([key, entryValue]) => {
49
+ const field = resolvedType.value.fields.find((candidate) => candidate.name === key);
50
+ return [key, field ? decodeValue(field.type, entryValue) : entryValue];
51
+ }));
52
+ case "optional": return decodeValue(resolvedType.value.type, value);
53
+ case "attachment":
54
+ case "union":
55
+ case "result":
56
+ case "unknown": return value;
57
+ case "ref": return decodeValue(resolveType(resolvedType), value);
58
+ }
59
+ };
60
+ const encodeValue = (type, value) => {
61
+ const resolvedType = resolveType(type);
62
+ if (value === void 0 || value === null) return null;
63
+ switch (resolvedType.kind) {
64
+ case "string":
65
+ case "boolean":
66
+ case "integer":
67
+ case "float":
68
+ case "double":
69
+ case "objectReference":
70
+ case "unknown": return value;
71
+ case "date":
72
+ if (value instanceof Temporal.PlainDate) return value.toString();
73
+ if (value instanceof Date) return value.toISOString().slice(0, 10);
74
+ return value;
75
+ case "timestamp":
76
+ if (value instanceof Temporal.Instant) return value.toString();
77
+ if (value instanceof Date) return value.toISOString();
78
+ return value;
79
+ case "geopoint": return encodeGeoPoint(value);
80
+ case "list":
81
+ if (!Array.isArray(value)) return value;
82
+ if (resolvedType.value.elementType.kind === "string") return value.map((item) => encodeValue(resolvedType.value.elementType, item)).filter((item) => {
83
+ return typeof item === "string" || typeof item === "number" || typeof item === "boolean";
84
+ }).join(";");
85
+ return value.map((item) => encodeValue(resolvedType.value.elementType, item));
86
+ case "map":
87
+ if (!isPlainObject(value)) return value;
88
+ return Object.fromEntries(Object.entries(value).map(([key, entryValue]) => [encodeValue(resolvedType.value.keyType, key), encodeValue(resolvedType.value.valueType, entryValue)]));
89
+ case "struct":
90
+ if (!isPlainObject(value)) return value;
91
+ return Object.fromEntries(Object.entries(value).map(([key, entryValue]) => {
92
+ const field = resolvedType.value.fields.find((candidate) => candidate.name === key);
93
+ return [key, field ? encodeValue(field.type, entryValue) : entryValue];
94
+ }));
95
+ case "optional": return encodeValue(resolvedType.value.type, value);
96
+ case "attachment":
97
+ case "union":
98
+ case "result": return value;
99
+ case "ref": return encodeValue(resolveType(resolvedType), value);
100
+ }
101
+ };
102
+ const decodeObjectType = (objectType, object) => {
103
+ const cleaned = stripAttributes(object);
104
+ return Object.fromEntries(objectType.properties.map((property) => [property.name, decodeValue(property.type, cleaned[property.name])]));
105
+ };
106
+ return {
107
+ decodeObject: (objectTypeName, object) => {
108
+ const objectType = objectTypes.get(objectTypeName);
109
+ if (!objectType) throw new Error(`Unknown object type "${objectTypeName}".`);
110
+ return decodeObjectType(objectType, object);
111
+ },
112
+ decodeValue,
113
+ encodeValue
114
+ };
181
115
  }
182
116
  function decodeGeoPoint(value) {
183
- if (isPlainObject(value)) {
184
- const lat = value.latitude ?? value.lat;
185
- const lon = value.longitude ?? value.lon;
186
- if (typeof lat === "number" && typeof lon === "number") {
187
- return { lat, lon };
188
- }
189
- }
190
- return value;
117
+ if (isPlainObject(value)) {
118
+ const lat = value.latitude ?? value.lat;
119
+ const lon = value.longitude ?? value.lon;
120
+ if (typeof lat === "number" && typeof lon === "number") return {
121
+ lat,
122
+ lon
123
+ };
124
+ }
125
+ return value;
191
126
  }
192
127
  function encodeGeoPoint(value) {
193
- if (isPlainObject(value) && typeof value.lat === "number" && typeof value.lon === "number") {
194
- return {
195
- latitude: value.lat,
196
- longitude: value.lon,
197
- };
198
- }
199
- return value;
128
+ if (isPlainObject(value) && typeof value.lat === "number" && typeof value.lon === "number") return {
129
+ latitude: value.lat,
130
+ longitude: value.lon
131
+ };
132
+ return value;
200
133
  }
134
+ //#endregion
135
+ export { createSalesforceCodec };
136
+
201
137
  //# sourceMappingURL=salesforceCodec.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"salesforceCodec.js","sourceRoot":"","sources":["../../src/adapter/salesforceCodec.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAW7C,SAAS,aAAa,CAAC,KAAc;IACjC,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;AAChF,CAAC;AAED,SAAS,eAAe,CAAC,MAA8B;IACnD,MAAM,EAAE,UAAU,EAAE,GAAG,IAAI,EAAE,GAAG,MAAM,CAAC;IACvC,KAAK,UAAU,CAAC;IAChB,OAAO,IAAI,CAAC;AAChB,CAAC;AAED,MAAM,UAAU,qBAAqB,CAAC,EAAc;IAChD,MAAM,WAAW,GAAG,IAAI,GAAG,CAAC,EAAE,CAAC,WAAW,CAAC,GAAG,CAAC,CAAC,UAAU,EAAE,EAAE,CAAC,CAAC,UAAU,CAA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,CAAC,IAAI,CAAC,CAAC;SACrD,CAAC,CACL,CAAC;IACN,CAAC,CAAC;IAEF,OAAO;QACH,YAAY,EAAE,CAAC,cAAc,EAAE,MAAM,EAAE,EAAE;YACrC,MAAM,UAAU,GAAG,WAAW,CAAC,GAAG,CAAC,cAAc,CAAC,CAAC;YACnD,IAAI,CAAC,UAAU,EAAE,CAAC;gBACd,MAAM,IAAI,KAAK,CAAC,wBAAwB,cAAc,IAAI,CAAC,CAAC;YAChE,CAAC;YACD,OAAO,gBAAgB,CAAC,UAAU,EAAE,MAAM,CAAC,CAAC;QAChD,CAAC;QACD,WAAW;QACX,WAAW;KACd,CAAC;AACN,CAAC;AAED,SAAS,cAAc,CAAC,KAAc;IAClC,IAAI,aAAa,CAAC,KAAK,CAAC,EAAE,CAAC;QACvB,MAAM,GAAG,GAAG,KAAK,CAAC,QAAQ,IAAI,KAAK,CAAC,GAAG,CAAC;QACxC,MAAM,GAAG,GAAG,KAAK,CAAC,SAAS,IAAI,KAAK,CAAC,GAAG,CAAC;QACzC,IAAI,OAAO,GAAG,KAAK,QAAQ,IAAI,OAAO,GAAG,KAAK,QAAQ,EAAE,CAAC;YACrD,OAAO,EAAE,GAAG,EAAE,GAAG,EAAE,CAAC;QACxB,CAAC;IACL,CAAC;IACD,OAAO,KAAK,CAAC;AACjB,CAAC;AAED,SAAS,cAAc,CAAC,KAAc;IAClC,IAAI,aAAa,CAAC,KAAK,CAAC,IAAI,OAAO,KAAK,CAAC,GAAG,KAAK,QAAQ,IAAI,OAAO,KAAK,CAAC,GAAG,KAAK,QAAQ,EAAE,CAAC;QACzF,OAAO;YACH,QAAQ,EAAE,KAAK,CAAC,GAAG;YACnB,SAAS,EAAE,KAAK,CAAC,GAAG;SACvB,CAAC;IACN,CAAC;IACD,OAAO,KAAK,CAAC;AACjB,CAAC"}
1
+ {"version":3,"file":"salesforceCodec.js","names":[],"sources":["../../src/adapter/salesforceCodec.ts"],"sourcesContent":["import { Temporal } from \"temporal-polyfill\";\nimport type { ObjectTypeDef, OntologyIR, TypeDef } from \"@party-stack/ontology\";\n\ntype SalesforceObjectRecord = Record<string, unknown>;\n\nexport interface SalesforceCodec {\n decodeObject: (objectType: string, object: SalesforceObjectRecord) => SalesforceObjectRecord;\n decodeValue: (type: TypeDef, value: unknown) => unknown;\n encodeValue: (type: TypeDef, value: unknown) => unknown;\n}\n\nfunction isPlainObject(value: unknown): value is Record<string, unknown> {\n return typeof value === \"object\" && value !== null && !Array.isArray(value);\n}\n\nfunction stripAttributes(object: SalesforceObjectRecord): SalesforceObjectRecord {\n const { attributes, ...rest } = object;\n void attributes;\n return rest;\n}\n\nexport function createSalesforceCodec(ir: OntologyIR): SalesforceCodec {\n const objectTypes = new Map(ir.objectTypes.map((objectType) => [objectType.name, objectType]));\n const namedTypes = new Map(ir.types.map((type) => [type.name, type.type]));\n\n const resolveType = (type: TypeDef, seen = new Set<string>()): TypeDef => {\n if (type.kind !== \"ref\") {\n return type;\n }\n\n const name = type.value.name;\n if (seen.has(name)) {\n throw new Error(`Circular ontology type reference \"${name}\".`);\n }\n\n const resolved = namedTypes.get(name);\n if (!resolved) {\n throw new Error(`Unknown ontology type reference \"${name}\".`);\n }\n\n return resolveType(resolved, new Set([...seen, name]));\n };\n\n const decodeValue = (type: TypeDef, value: unknown): unknown => {\n const resolvedType = resolveType(type);\n\n if (value === undefined || value === null) {\n if (resolvedType.kind === \"optional\") {\n return undefined;\n }\n return value;\n }\n\n switch (resolvedType.kind) {\n case \"string\":\n return value;\n case \"boolean\":\n return typeof value === \"string\" ? value === \"true\" : value;\n case \"integer\":\n case \"float\":\n case \"double\":\n return typeof value === \"string\" ? Number(value) : value;\n case \"date\":\n return typeof value === \"string\" ? Temporal.PlainDate.from(value) : value;\n case \"timestamp\":\n if (typeof value === \"string\") {\n // Salesforce datetime wire format is typically ISO-8601.\n return Temporal.Instant.from(\n value.endsWith(\"Z\") || value.includes(\"+\") ? value : `${value}Z`\n );\n }\n if (typeof value === \"number\") return Temporal.Instant.fromEpochMilliseconds(value);\n return value;\n case \"geopoint\":\n return decodeGeoPoint(value);\n case \"objectReference\":\n return value;\n case \"list\":\n if (typeof value === \"string\") {\n // Multipicklist values are semicolon-delimited.\n return value\n .split(\";\")\n .filter((entry) => entry.length > 0)\n .map((item) => decodeValue(resolvedType.value.elementType, item));\n }\n return Array.isArray(value)\n ? value.map((item) => decodeValue(resolvedType.value.elementType, item))\n : value;\n case \"map\":\n if (!isPlainObject(value)) {\n return value;\n }\n return Object.fromEntries(\n Object.entries(value).map(([key, entryValue]) => [\n decodeValue(resolvedType.value.keyType, key),\n decodeValue(resolvedType.value.valueType, entryValue),\n ])\n );\n case \"struct\":\n if (!isPlainObject(value)) {\n return value;\n }\n return Object.fromEntries(\n Object.entries(stripAttributes(value)).map(([key, entryValue]) => {\n const field = resolvedType.value.fields.find((candidate) => candidate.name === key);\n return [key, field ? decodeValue(field.type, entryValue) : entryValue];\n })\n );\n case \"optional\":\n return decodeValue(resolvedType.value.type, value);\n case \"attachment\":\n case \"union\":\n case \"result\":\n case \"unknown\":\n return value;\n case \"ref\":\n return decodeValue(resolveType(resolvedType), value);\n }\n };\n\n const encodeValue = (type: TypeDef, value: unknown): unknown => {\n const resolvedType = resolveType(type);\n\n if (value === undefined || value === null) {\n return null;\n }\n\n switch (resolvedType.kind) {\n case \"string\":\n case \"boolean\":\n case \"integer\":\n case \"float\":\n case \"double\":\n case \"objectReference\":\n case \"unknown\":\n return value;\n case \"date\":\n if (value instanceof Temporal.PlainDate) return value.toString();\n if (value instanceof Date) return value.toISOString().slice(0, 10);\n return value;\n case \"timestamp\":\n if (value instanceof Temporal.Instant) return value.toString();\n if (value instanceof Date) return value.toISOString();\n return value;\n case \"geopoint\":\n return encodeGeoPoint(value);\n case \"list\":\n if (!Array.isArray(value)) return value;\n // Multipicklist wire format uses semicolon delimiters for string lists.\n if (resolvedType.value.elementType.kind === \"string\") {\n return value\n .map((item) => encodeValue(resolvedType.value.elementType, item))\n .filter((item): item is string | number | boolean => {\n return (\n typeof item === \"string\" ||\n typeof item === \"number\" ||\n typeof item === \"boolean\"\n );\n })\n .join(\";\");\n }\n return value.map((item) => encodeValue(resolvedType.value.elementType, item));\n case \"map\":\n if (!isPlainObject(value)) return value;\n return Object.fromEntries(\n Object.entries(value).map(([key, entryValue]) => [\n encodeValue(resolvedType.value.keyType, key),\n encodeValue(resolvedType.value.valueType, entryValue),\n ])\n );\n case \"struct\":\n if (!isPlainObject(value)) return value;\n return Object.fromEntries(\n Object.entries(value).map(([key, entryValue]) => {\n const field = resolvedType.value.fields.find((candidate) => candidate.name === key);\n return [key, field ? encodeValue(field.type, entryValue) : entryValue];\n })\n );\n case \"optional\":\n return encodeValue(resolvedType.value.type, value);\n case \"attachment\":\n case \"union\":\n case \"result\":\n return value;\n case \"ref\":\n return encodeValue(resolveType(resolvedType), value);\n }\n };\n\n const decodeObjectType = (\n objectType: ObjectTypeDef,\n object: SalesforceObjectRecord\n ): SalesforceObjectRecord => {\n const cleaned = stripAttributes(object);\n return Object.fromEntries(\n objectType.properties.map((property) => [\n property.name,\n decodeValue(property.type, cleaned[property.name]),\n ])\n );\n };\n\n return {\n decodeObject: (objectTypeName, object) => {\n const objectType = objectTypes.get(objectTypeName);\n if (!objectType) {\n throw new Error(`Unknown object type \"${objectTypeName}\".`);\n }\n return decodeObjectType(objectType, object);\n },\n decodeValue,\n encodeValue,\n };\n}\n\nfunction decodeGeoPoint(value: unknown): unknown {\n if (isPlainObject(value)) {\n const lat = value.latitude ?? value.lat;\n const lon = value.longitude ?? value.lon;\n if (typeof lat === \"number\" && typeof lon === \"number\") {\n return { lat, lon };\n }\n }\n return value;\n}\n\nfunction encodeGeoPoint(value: unknown): unknown {\n if (isPlainObject(value) && typeof value.lat === \"number\" && typeof value.lon === \"number\") {\n return {\n latitude: value.lat,\n longitude: value.lon,\n };\n }\n return value;\n}\n"],"mappings":";;AAWA,SAAS,cAAc,OAAkD;CACrE,OAAO,OAAO,UAAU,YAAY,UAAU,Q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,UAAU,IAAI,UAAU;IACzE,CAAC,CACL;GACJ,KAAK,YACD,OAAO,YAAY,aAAa,MAAM,MAAM,KAAK;GACrD,KAAK;GACL,KAAK;GACL,KAAK,UACD,OAAO;GACX,KAAK,OACD,OAAO,YAAY,YAAY,YAAY,GAAG,KAAK;EAC3D;CACJ;CAEA,MAAM,oBACF,YACA,WACyB;EACzB,MAAM,UAAU,gBAAgB,MAAM;EACtC,OAAO,OAAO,YACV,WAAW,WAAW,KAAK,aAAa,CACpC,SAAS,MACT,YAAY,SAAS,MAAM,QAAQ,SAAS,KAAK,CACrD,CAAC,CACL;CACJ;CAEA,OAAO;EACH,eAAe,gBAAgB,WAAW;GACtC,MAAM,aAAa,YAAY,IAAI,cAAc;GACjD,IAAI,CAAC,YACD,MAAM,IAAI,MAAM,wBAAwB,eAAe,GAAG;GAE9D,OAAO,iBAAiB,YAAY,MAAM;EAC9C;EACA;EACA;CACJ;AACJ;AAEA,SAAS,eAAe,OAAyB;CAC7C,IAAI,cAAc,KAAK,GAAG;EACtB,MAAM,MAAM,MAAM,YAAY,MAAM;EACpC,MAAM,MAAM,MAAM,aAAa,MAAM;EACrC,IAAI,OAAO,QAAQ,YAAY,OAAO,QAAQ,UAC1C,OAAO;GAAE;GAAK;EAAI;CAE1B;CACA,OAAO;AACX;AAEA,SAAS,eAAe,OAAyB;CAC7C,IAAI,cAAc,KAAK,KAAK,OAAO,MAAM,QAAQ,YAAY,OAAO,MAAM,QAAQ,UAC9E,OAAO;EACH,UAAU,MAAM;EAChB,WAAW,MAAM;CACrB;CAEJ,OAAO;AACX"}
@@ -1,28 +1,30 @@
1
- import type { OntologyPullConfig, OntologyPullSource, OntologyIR } from "@party-stack/ontology";
2
- import { type SalesforceAuthenticationClient, type SalesforceOAuthConnectionOptions } from "../connection.js";
3
- import type { SalesforceCrudActionTypeSelection } from "../crud.js";
1
+ import { SalesforceAuthenticationClient, SalesforceOAuthConnectionOptions } from "../connection.js";
2
+ import { SalesforceCrudActionTypeSelection } from "../crud.js";
3
+ import { OntologyIR, OntologyPullConfig, OntologyPullSource } from "@party-stack/ontology";
4
+ //#region src/config/index.d.ts
4
5
  export interface SalesforceOntologyPullConnectionOptions {
5
- oauth?: SalesforceOAuthConnectionOptions;
6
- token?: string;
7
- userId?: string;
6
+ oauth?: SalesforceOAuthConnectionOptions;
7
+ token?: string;
8
+ userId?: string;
8
9
  }
9
10
  export interface CreateSalesforceOntologyPullSourceOptions {
10
- instanceUrl: string;
11
- apiVersion: string;
12
- ontologyId: string;
13
- objectTypeNames: string[];
14
- flowActionTypeNames?: string[];
15
- standardActionTypeNames?: string[];
16
- standardQueryFunctionTypeNames?: string[];
17
- crudActionTypes?: readonly SalesforceCrudActionTypeSelection[];
18
- connection: SalesforceOntologyPullConnectionOptions;
19
- transformPulledOntology?: (ontology: OntologyIR) => OntologyIR | Promise<OntologyIR>;
11
+ instanceUrl: string;
12
+ apiVersion: string;
13
+ ontologyId: string;
14
+ objectTypeNames: string[];
15
+ flowActionTypeNames?: string[];
16
+ standardActionTypeNames?: string[];
17
+ standardQueryFunctionTypeNames?: string[];
18
+ crudActionTypes?: readonly SalesforceCrudActionTypeSelection[];
19
+ connection: SalesforceOntologyPullConnectionOptions;
20
+ transformPulledOntology?: (ontology: OntologyIR) => OntologyIR | Promise<OntologyIR>;
20
21
  }
21
22
  export declare function createSalesforceOntologyPullSource(options: CreateSalesforceOntologyPullSourceOptions): OntologyPullSource<SalesforceAuthenticationClient>;
22
23
  export type SalesforceOntologyPullConfig = OntologyPullConfig<SalesforceAuthenticationClient>;
23
24
  export interface CreateSalesforceOntologyPullConfigOptions extends CreateSalesforceOntologyPullSourceOptions {
24
- flowActionTypeNames: string[];
25
- queryFunctionTypeNames?: string[];
25
+ flowActionTypeNames: string[];
26
+ queryFunctionTypeNames?: string[];
26
27
  }
27
28
  export declare function createSalesforceOntologyPullConfig(options: CreateSalesforceOntologyPullConfigOptions): SalesforceOntologyPullConfig;
29
+ //#endregion
28
30
  //# sourceM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