@stoker-platform/utils 0.2.1

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 (126) hide show
  1. package/lib/src/access/collection.d.ts +9 -0
  2. package/lib/src/access/collection.js +59 -0
  3. package/lib/src/access/document.d.ts +3 -0
  4. package/lib/src/access/document.js +191 -0
  5. package/lib/src/access/getCollectionRestrictions.d.ts +7 -0
  6. package/lib/src/access/getCollectionRestrictions.js +71 -0
  7. package/lib/src/access/getRecordSubcollections.d.ts +2 -0
  8. package/lib/src/access/getRecordSubcollections.js +15 -0
  9. package/lib/src/access/getRelatedCollections.d.ts +2 -0
  10. package/lib/src/access/getRelatedCollections.js +24 -0
  11. package/lib/src/access/hasDependencyAccess.d.ts +2 -0
  12. package/lib/src/access/hasDependencyAccess.js +24 -0
  13. package/lib/src/access/isPaginationEnabled.d.ts +2 -0
  14. package/lib/src/access/isPaginationEnabled.js +35 -0
  15. package/lib/src/access/permissions.d.ts +2 -0
  16. package/lib/src/access/permissions.js +543 -0
  17. package/lib/src/access/read/getOne.d.ts +2 -0
  18. package/lib/src/access/read/getOne.js +19 -0
  19. package/lib/src/access/read/getSome.d.ts +2 -0
  20. package/lib/src/access/read/getSome.js +21 -0
  21. package/lib/src/access/roleHasOperationAccess.d.ts +2 -0
  22. package/lib/src/access/roleHasOperationAccess.js +7 -0
  23. package/lib/src/access/write/addRecord.d.ts +2 -0
  24. package/lib/src/access/write/addRecord.js +40 -0
  25. package/lib/src/access/write/deleteRecord.d.ts +2 -0
  26. package/lib/src/access/write/deleteRecord.js +26 -0
  27. package/lib/src/access/write/updateRecord.d.ts +2 -0
  28. package/lib/src/access/write/updateRecord.js +61 -0
  29. package/lib/src/getConfigValue.d.ts +12 -0
  30. package/lib/src/getConfigValue.js +83 -0
  31. package/lib/src/getCustomization.d.ts +4 -0
  32. package/lib/src/getCustomization.js +29 -0
  33. package/lib/src/getFieldCustomization.d.ts +7 -0
  34. package/lib/src/getFieldCustomization.js +3 -0
  35. package/lib/src/main.d.ts +60 -0
  36. package/lib/src/main.js +60 -0
  37. package/lib/src/operations/addInitialValues.d.ts +2 -0
  38. package/lib/src/operations/addInitialValues.js +27 -0
  39. package/lib/src/operations/addLowercaseFields.d.ts +2 -0
  40. package/lib/src/operations/addLowercaseFields.js +12 -0
  41. package/lib/src/operations/addRelationArrays.d.ts +2 -0
  42. package/lib/src/operations/addRelationArrays.js +60 -0
  43. package/lib/src/operations/addSystemFields.d.ts +2 -0
  44. package/lib/src/operations/addSystemFields.js +17 -0
  45. package/lib/src/operations/getDateRange.d.ts +5 -0
  46. package/lib/src/operations/getDateRange.js +56 -0
  47. package/lib/src/operations/getExtendedSchema.d.ts +2 -0
  48. package/lib/src/operations/getExtendedSchema.js +23 -0
  49. package/lib/src/operations/getFinalRecord.d.ts +1 -0
  50. package/lib/src/operations/getFinalRecord.js +11 -0
  51. package/lib/src/operations/getInputSchema.d.ts +15 -0
  52. package/lib/src/operations/getInputSchema.js +352 -0
  53. package/lib/src/operations/getLowercaseFields.d.ts +2 -0
  54. package/lib/src/operations/getLowercaseFields.js +15 -0
  55. package/lib/src/operations/getSingleFieldRelations.d.ts +2 -0
  56. package/lib/src/operations/getSingleFieldRelations.js +27 -0
  57. package/lib/src/operations/getZodSchema.d.ts +15 -0
  58. package/lib/src/operations/getZodSchema.js +303 -0
  59. package/lib/src/operations/isDeleteSentinel.d.ts +1 -0
  60. package/lib/src/operations/isDeleteSentinel.js +4 -0
  61. package/lib/src/operations/isSortingEnabled.d.ts +2 -0
  62. package/lib/src/operations/isSortingEnabled.js +7 -0
  63. package/lib/src/operations/isValidUniqueFieldValue.d.ts +1 -0
  64. package/lib/src/operations/isValidUniqueFieldValue.js +25 -0
  65. package/lib/src/operations/parseDate.d.ts +1 -0
  66. package/lib/src/operations/parseDate.js +4 -0
  67. package/lib/src/operations/prepareDenormalized.d.ts +8 -0
  68. package/lib/src/operations/prepareDenormalized.js +312 -0
  69. package/lib/src/operations/removeDeleteSentinels.d.ts +2 -0
  70. package/lib/src/operations/removeDeleteSentinels.js +15 -0
  71. package/lib/src/operations/removeDeletedFields.d.ts +2 -0
  72. package/lib/src/operations/removeDeletedFields.js +14 -0
  73. package/lib/src/operations/removeEmptyStrings.d.ts +2 -0
  74. package/lib/src/operations/removeEmptyStrings.js +14 -0
  75. package/lib/src/operations/removePrivateFields.d.ts +2 -0
  76. package/lib/src/operations/removePrivateFields.js +14 -0
  77. package/lib/src/operations/removeUndefined.d.ts +2 -0
  78. package/lib/src/operations/removeUndefined.js +14 -0
  79. package/lib/src/operations/retryOperation.d.ts +1 -0
  80. package/lib/src/operations/retryOperation.js +21 -0
  81. package/lib/src/operations/runHooks.d.ts +17 -0
  82. package/lib/src/operations/runHooks.js +18 -0
  83. package/lib/src/operations/sanitizeDownloadFilename.d.ts +1 -0
  84. package/lib/src/operations/sanitizeDownloadFilename.js +18 -0
  85. package/lib/src/operations/sanitizeEmailInput.d.ts +5 -0
  86. package/lib/src/operations/sanitizeEmailInput.js +73 -0
  87. package/lib/src/operations/updateFieldReference.d.ts +2 -0
  88. package/lib/src/operations/updateFieldReference.js +14 -0
  89. package/lib/src/operations/validateRecord.d.ts +2 -0
  90. package/lib/src/operations/validateRecord.js +18 -0
  91. package/lib/src/operations/validateStorageName.d.ts +1 -0
  92. package/lib/src/operations/validateStorageName.js +19 -0
  93. package/lib/src/schema/getAccessFields.d.ts +2 -0
  94. package/lib/src/schema/getAccessFields.js +62 -0
  95. package/lib/src/schema/getCollection.d.ts +2 -0
  96. package/lib/src/schema/getCollection.js +3 -0
  97. package/lib/src/schema/getDependencyFields.d.ts +6 -0
  98. package/lib/src/schema/getDependencyFields.js +22 -0
  99. package/lib/src/schema/getField.d.ts +2 -0
  100. package/lib/src/schema/getField.js +3 -0
  101. package/lib/src/schema/getFieldNames.d.ts +2 -0
  102. package/lib/src/schema/getFieldNames.js +3 -0
  103. package/lib/src/schema/getIndexFields.d.ts +9 -0
  104. package/lib/src/schema/getIndexFields.js +184 -0
  105. package/lib/src/schema/getInverseRelationType.d.ts +1 -0
  106. package/lib/src/schema/getInverseRelationType.js +15 -0
  107. package/lib/src/schema/getPathCollections.d.ts +2 -0
  108. package/lib/src/schema/getPathCollections.js +12 -0
  109. package/lib/src/schema/getRecordSystemFields.d.ts +2 -0
  110. package/lib/src/schema/getRecordSystemFields.js +11 -0
  111. package/lib/src/schema/getRelationLists.d.ts +5 -0
  112. package/lib/src/schema/getRelationLists.js +13 -0
  113. package/lib/src/schema/getSubcollections.d.ts +2 -0
  114. package/lib/src/schema/getSubcollections.js +9 -0
  115. package/lib/src/schema/getSystemFieldsSchema.d.ts +2 -0
  116. package/lib/src/schema/getSystemFieldsSchema.js +52 -0
  117. package/lib/src/schema/isDependencyField.d.ts +2 -0
  118. package/lib/src/schema/isDependencyField.js +18 -0
  119. package/lib/src/schema/isIncludedField.d.ts +2 -0
  120. package/lib/src/schema/isIncludedField.js +18 -0
  121. package/lib/src/schema/isRelationField.d.ts +2 -0
  122. package/lib/src/schema/isRelationField.js +3 -0
  123. package/lib/src/schema/system-fields.d.ts +2 -0
  124. package/lib/src/schema/system-fields.js +13 -0
  125. package/lib/tsconfig.tsbuildinfo +1 -0
  126. package/package.json +35 -0
@@ -0,0 +1,62 @@
1
+ import { getField } from "./getField.js";
2
+ import { getSystemFieldsSchema } from "./getSystemFieldsSchema.js";
3
+ export const getAccessFields = (collection, role) => {
4
+ const indexFields = [];
5
+ const { access, fields } = collection;
6
+ const { attributeRestrictions, entityRestrictions } = access;
7
+ const systemFieldsSchema = getSystemFieldsSchema();
8
+ if (attributeRestrictions) {
9
+ attributeRestrictions.forEach((attributeRestriction) => {
10
+ if (!attributeRestriction.roles.some((accessRole) => accessRole.role === role))
11
+ return;
12
+ switch (attributeRestriction.type) {
13
+ case "Record_Owner":
14
+ indexFields.push(getField(systemFieldsSchema, "Created_By"));
15
+ break;
16
+ case "Record_User":
17
+ indexFields.push(getField(fields, attributeRestriction.collectionField));
18
+ break;
19
+ case "Record_Property":
20
+ indexFields.push(getField(fields, attributeRestriction.propertyField));
21
+ break;
22
+ }
23
+ });
24
+ }
25
+ if (entityRestrictions) {
26
+ entityRestrictions.restrictions?.forEach((entityRestriction) => {
27
+ if (!entityRestriction.roles.some((accessRole) => accessRole.role === role))
28
+ return;
29
+ switch (entityRestriction.type) {
30
+ case "Individual":
31
+ indexFields.push(getField(systemFieldsSchema, "id"));
32
+ break;
33
+ case "Parent":
34
+ indexFields.push(getField(fields, entityRestriction.collectionField));
35
+ break;
36
+ case "Parent_Property":
37
+ indexFields.push(getField(fields, entityRestriction.collectionField));
38
+ indexFields.push(getField(fields, entityRestriction.propertyField));
39
+ break;
40
+ }
41
+ });
42
+ if (entityRestrictions.parentFilters) {
43
+ entityRestrictions.parentFilters.forEach((parentFilter) => {
44
+ if (!parentFilter.roles.some((accessRole) => accessRole.role === role))
45
+ return;
46
+ switch (parentFilter.type) {
47
+ case "Individual":
48
+ indexFields.push(getField(fields, parentFilter.collectionField));
49
+ break;
50
+ case "Parent":
51
+ indexFields.push(getField(fields, parentFilter.parentCollectionField));
52
+ break;
53
+ case "Parent_Property":
54
+ indexFields.push(getField(fields, parentFilter.parentCollectionField));
55
+ indexFields.push(getField(fields, parentFilter.parentPropertyField));
56
+ break;
57
+ }
58
+ });
59
+ }
60
+ }
61
+ return [...new Set(indexFields)];
62
+ };
@@ -0,0 +1,2 @@
1
+ import type { CollectionSchema } from "@stoker-platform/types";
2
+ export declare const getCollection: (collections: CollectionSchema[], collectionName: string) => CollectionSchema;
@@ -0,0 +1,3 @@
1
+ export const getCollection = (collections, collectionName) => {
2
+ return collections.filter((collection) => collection.labels.collection === collectionName)[0];
3
+ };
@@ -0,0 +1,6 @@
1
+ import { CollectionSchema, CollectionsSchema } from "@stoker-platform/types";
2
+ export declare const getDependencyFields: (collection: CollectionSchema, schema: CollectionsSchema) => {
3
+ [field: string]: {
4
+ [collection: string]: string[];
5
+ };
6
+ };
@@ -0,0 +1,22 @@
1
+ import { isRelationField } from "./isRelationField.js";
2
+ export const getDependencyFields = (collection, schema) => {
3
+ const collections = Object.values(schema.collections);
4
+ const { labels } = collection;
5
+ const dependentFields = {};
6
+ collections.forEach((collectionSchema) => {
7
+ const { labels: dependencyName, fields: dependencyFields } = collectionSchema;
8
+ dependencyFields.forEach((field) => {
9
+ if (isRelationField(field) && field.collection === labels.collection && field.dependencyFields) {
10
+ field.dependencyFields.forEach((dependencyField) => {
11
+ dependentFields[dependencyField.field] ||= {};
12
+ dependentFields[dependencyField.field][dependencyName.collection] ||= [];
13
+ dependentFields[dependencyField.field][dependencyName.collection] = dependentFields[dependencyField.field][dependencyName.collection].concat(dependencyField.roles);
14
+ dependentFields[dependencyField.field][dependencyName.collection] = [
15
+ ...new Set(dependentFields[dependencyField.field][dependencyName.collection]),
16
+ ];
17
+ });
18
+ }
19
+ });
20
+ });
21
+ return dependentFields;
22
+ };
@@ -0,0 +1,2 @@
1
+ import type { CollectionField } from "@stoker-platform/types";
2
+ export declare const getField: (fields: CollectionField[], fieldName: string | undefined) => CollectionField;
@@ -0,0 +1,3 @@
1
+ export const getField = (fields, fieldName) => {
2
+ return fields.filter((field) => field.name === fieldName)[0];
3
+ };
@@ -0,0 +1,2 @@
1
+ import type { CollectionField } from "@stoker-platform/types";
2
+ export declare const getFieldNames: (fields: CollectionField[]) => string;
@@ -0,0 +1,3 @@
1
+ export const getFieldNames = (fields) => {
2
+ return JSON.stringify(fields.map((field) => field.name));
3
+ };
@@ -0,0 +1,9 @@
1
+ import type { CollectionField, CollectionSchema, CollectionsSchema, StokerPermissions, StokerRole, RoleGroup } from "@stoker-platform/types";
2
+ export declare const getRoleFields: (collection: CollectionSchema, role: StokerRole) => CollectionField[];
3
+ export declare const getDependencyAccessFields: (field: CollectionField, collection: CollectionSchema, schema: CollectionsSchema) => CollectionField[];
4
+ export declare const getDependencyIndexFields: (field: CollectionField, collection: CollectionSchema, schema: CollectionsSchema) => CollectionField[];
5
+ export declare const getRoleGroups: (collection: CollectionSchema, schema: CollectionsSchema) => Set<RoleGroup>;
6
+ export declare const getRoleGroup: (role: StokerRole, collection: CollectionSchema, schema: CollectionsSchema) => RoleGroup | undefined;
7
+ export declare const getRoleExcludedFields: (roleGroup: RoleGroup, collection: CollectionSchema) => CollectionField[];
8
+ export declare const getUserRoleGroups: (schema: CollectionsSchema, permissions: StokerPermissions, collections: string[]) => Record<string, RoleGroup>;
9
+ export declare const getAllRoleGroups: (schema: CollectionsSchema, permissions?: StokerPermissions, collections?: string[]) => Record<string, Set<RoleGroup>>;
@@ -0,0 +1,184 @@
1
+ import { getField } from "./getField.js";
2
+ import { getSystemFieldsSchema } from "./getSystemFieldsSchema.js";
3
+ import { systemFields } from "./system-fields.js";
4
+ import { getAccessFields } from "./getAccessFields.js";
5
+ import { getDependencyFields } from "./getDependencyFields.js";
6
+ import { roleHasOperationAccess } from "../access/roleHasOperationAccess.js";
7
+ export const getRoleFields = (collection, role) => {
8
+ const indexFields = [];
9
+ const { fields, roleSystemFields, preloadCache, queries } = collection;
10
+ const systemFieldsSchema = getSystemFieldsSchema();
11
+ indexFields.push({
12
+ name: "Collection_Path",
13
+ type: "Array",
14
+ required: true,
15
+ });
16
+ fields.forEach((field) => {
17
+ if (!field.access || field.access.includes(role)) {
18
+ indexFields.push(field);
19
+ }
20
+ });
21
+ roleSystemFields
22
+ ?.filter((systemField) => (!systemField.roles || systemField.roles.includes(role)) && systemField.field !== "Collection_Path")
23
+ .forEach((systemField) => {
24
+ indexFields.push(getField(systemFieldsSchema, systemField.field));
25
+ });
26
+ if (preloadCache?.range) {
27
+ preloadCache.range.fields.forEach((field) => {
28
+ if (systemFields.includes(field)) {
29
+ indexFields.push(getField(systemFieldsSchema, field));
30
+ }
31
+ });
32
+ }
33
+ queries?.forEach((query) => {
34
+ const queryField = getField(fields.concat(systemFieldsSchema), query.field);
35
+ if ((!query.roles || query.roles.includes(role)) &&
36
+ queryField &&
37
+ (!queryField.access || queryField.access?.includes(role)) &&
38
+ systemFields.includes(query.field)) {
39
+ indexFields.push(getField(systemFieldsSchema, query.field));
40
+ }
41
+ });
42
+ const accessFields = getAccessFields(collection, role);
43
+ accessFields.forEach((field) => {
44
+ if (systemFields.includes(field.name)) {
45
+ indexFields.push(getField(systemFieldsSchema, field.name));
46
+ }
47
+ });
48
+ return [...new Set(indexFields)];
49
+ };
50
+ export const getDependencyAccessFields = (field, collection, schema) => {
51
+ const indexFields = [];
52
+ const { fields, preloadCache } = collection;
53
+ const systemFieldsSchema = getSystemFieldsSchema();
54
+ if (preloadCache?.range) {
55
+ preloadCache.range.fields.forEach((field) => {
56
+ if (systemFields.includes(field)) {
57
+ indexFields.push(getField(systemFieldsSchema, field));
58
+ }
59
+ else {
60
+ indexFields.push(getField(fields, field));
61
+ }
62
+ });
63
+ }
64
+ const dependentRoles = new Set();
65
+ const dependentFields = getDependencyFields(collection, schema);
66
+ Object.entries(dependentFields).map(([fieldName, collectionValues]) => {
67
+ if (field.name === fieldName) {
68
+ Object.values(collectionValues).forEach((roles) => {
69
+ roles.forEach((role) => {
70
+ dependentRoles.add(role);
71
+ });
72
+ });
73
+ }
74
+ });
75
+ dependentRoles.forEach((role) => {
76
+ indexFields.push(...getAccessFields(collection, role));
77
+ });
78
+ return [...new Set(indexFields)];
79
+ };
80
+ export const getDependencyIndexFields = (field, collection, schema) => {
81
+ const indexFields = [];
82
+ const { fields, softDelete } = collection;
83
+ indexFields.push({
84
+ name: "Collection_Path",
85
+ type: "Array",
86
+ required: true,
87
+ });
88
+ indexFields.push({
89
+ name: "id",
90
+ type: "String",
91
+ required: true,
92
+ });
93
+ if (softDelete) {
94
+ const softDeleteField = getField(fields, softDelete.archivedField);
95
+ if (softDeleteField) {
96
+ indexFields.push(softDeleteField);
97
+ }
98
+ }
99
+ indexFields.push(...getDependencyAccessFields(field, collection, schema));
100
+ return [...new Set(indexFields)];
101
+ };
102
+ export const getRoleGroups = (collection, schema) => {
103
+ const { preloadCache } = collection;
104
+ const roleGroups = new Set();
105
+ for (const role of schema.config.roles) {
106
+ if (!roleHasOperationAccess(collection, role, "read"))
107
+ continue;
108
+ const roleFields = getRoleFields(collection, role);
109
+ let found = false;
110
+ if (roleGroups.size === 0) {
111
+ roleGroups.add({ key: "1", roles: [role], fields: roleFields });
112
+ found = true;
113
+ }
114
+ else {
115
+ for (const group of roleGroups) {
116
+ if (roleFields.length === group.fields.length &&
117
+ roleFields.every((field) => group.fields.some((groupField) => groupField.name === field.name)) &&
118
+ !!preloadCache?.roles.includes(role) ===
119
+ !!group.roles.every((groupRole) => preloadCache?.roles.includes(groupRole))) {
120
+ group.roles.push(role);
121
+ found = true;
122
+ }
123
+ }
124
+ }
125
+ if (!found) {
126
+ roleGroups.add({ key: (roleGroups.size + 1).toString(), roles: [role], fields: roleFields });
127
+ }
128
+ }
129
+ return roleGroups;
130
+ };
131
+ export const getRoleGroup = (role, collection, schema) => {
132
+ const roleGroups = getRoleGroups(collection, schema);
133
+ for (const group of roleGroups.values()) {
134
+ if (group.roles.includes(role)) {
135
+ return group;
136
+ }
137
+ }
138
+ return;
139
+ };
140
+ export const getRoleExcludedFields = (roleGroup, collection) => {
141
+ const { fields } = collection;
142
+ const systemFieldsSchema = getSystemFieldsSchema();
143
+ const excludedFields = [];
144
+ const allFields = [...fields, ...systemFieldsSchema.filter((field) => field.name !== "id")];
145
+ allFields.forEach((field) => {
146
+ if (!roleGroup?.fields.some((groupField) => groupField.name === field.name)) {
147
+ excludedFields.push(field);
148
+ }
149
+ });
150
+ return excludedFields;
151
+ };
152
+ export const getUserRoleGroups = (schema, permissions, collections) => {
153
+ const userRoleGroups = {};
154
+ Object.values(schema.collections).forEach((collection) => {
155
+ if (!collections.includes(collection.labels.collection))
156
+ return;
157
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
158
+ const roleGroup = getRoleGroup(permissions.Role, collection, schema);
159
+ if (roleGroup) {
160
+ userRoleGroups[collection.labels.collection] = roleGroup;
161
+ }
162
+ });
163
+ return userRoleGroups;
164
+ };
165
+ export const getAllRoleGroups = (schema, permissions, collections) => {
166
+ const allRoleGroups = {};
167
+ Object.values(schema.collections).forEach((collection) => {
168
+ if (collections && !collections.includes(collection.labels.collection))
169
+ return;
170
+ const roleGroups = getRoleGroups(collection, schema);
171
+ const roleGroupsArray = Array.from(roleGroups);
172
+ roleGroupsArray.map((roleGroup) => {
173
+ roleGroup.fields.forEach((field) => {
174
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
175
+ if (permissions && field.access && !field.access?.includes(permissions.Role)) {
176
+ roleGroup.fields = roleGroup.fields.filter((groupField) => groupField.name !== field.name);
177
+ }
178
+ });
179
+ return roleGroup;
180
+ });
181
+ allRoleGroups[collection.labels.collection] = new Set(roleGroupsArray);
182
+ });
183
+ return allRoleGroups;
184
+ };
@@ -0,0 +1 @@
1
+ export declare const getInverseRelationType: (relationType: "OneToOne" | "OneToMany" | "ManyToOne" | "ManyToMany") => "OneToOne" | "OneToMany" | "ManyToOne" | "ManyToMany";
@@ -0,0 +1,15 @@
1
+ export const getInverseRelationType = (relationType) => {
2
+ if (relationType === "OneToOne") {
3
+ return "OneToOne";
4
+ }
5
+ if (relationType === "OneToMany") {
6
+ return "ManyToOne";
7
+ }
8
+ if (relationType === "ManyToOne") {
9
+ return "OneToMany";
10
+ }
11
+ if (relationType === "ManyToMany") {
12
+ return "ManyToMany";
13
+ }
14
+ return "OneToOne";
15
+ };
@@ -0,0 +1,2 @@
1
+ import { CollectionSchema, CollectionsSchema } from "@stoker-platform/types";
2
+ export declare const getPathCollections: (collection: CollectionSchema, schema: CollectionsSchema) => CollectionSchema[];
@@ -0,0 +1,12 @@
1
+ export const getPathCollections = (collection, schema) => {
2
+ const path = [collection];
3
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
4
+ const getParentPath = (collection) => {
5
+ if (collection.parentCollection) {
6
+ path.unshift(schema.collections[collection.parentCollection]);
7
+ getParentPath(schema.collections[collection.parentCollection]);
8
+ }
9
+ };
10
+ getParentPath(collection);
11
+ return path;
12
+ };
@@ -0,0 +1,2 @@
1
+ import { StokerRecord } from "@stoker-platform/types";
2
+ export declare const getRecordSystemFields: (record: StokerRecord) => Record<string, unknown>;
@@ -0,0 +1,11 @@
1
+ export const getRecordSystemFields = (record) => {
2
+ const systemFields = {
3
+ Last_Write_At: record.Last_Write_At,
4
+ Last_Write_By: record.Last_Write_By,
5
+ Last_Write_Connection_Status: record.Last_Write_Connection_Status,
6
+ Last_Write_Version: record.Last_Write_Version,
7
+ Last_Write_App: record.Last_Write_App,
8
+ Last_Save_At: record.Last_Save_At,
9
+ };
10
+ return systemFields;
11
+ };
@@ -0,0 +1,5 @@
1
+ import { CollectionSchema, StokerCollection } from "@stoker-platform/types";
2
+ export declare const getRelationLists: (collection: StokerCollection, collections: CollectionSchema[]) => Map<string, {
3
+ field: string;
4
+ roles: string[];
5
+ }>;
@@ -0,0 +1,13 @@
1
+ export const getRelationLists = (collection, collections) => {
2
+ const fields = new Map();
3
+ for (const collectionSchema of collections) {
4
+ if (collectionSchema.relationLists) {
5
+ for (const relationList of collectionSchema.relationLists) {
6
+ if (relationList.collection === collection) {
7
+ fields.set(relationList.field, { field: relationList.field, roles: relationList.roles || [] });
8
+ }
9
+ }
10
+ }
11
+ }
12
+ return fields;
13
+ };
@@ -0,0 +1,2 @@
1
+ import { CollectionSchema, CollectionsSchema } from "@stoker-platform/types";
2
+ export declare const getSubcollections: (schema: CollectionsSchema, collectionSchema: CollectionSchema) => string[];
@@ -0,0 +1,9 @@
1
+ export const getSubcollections = (schema, collectionSchema) => {
2
+ const subcollections = [];
3
+ Object.values(schema.collections).forEach((collection) => {
4
+ if (collection.parentCollection === collectionSchema.labels.collection) {
5
+ subcollections.push(collection.labels.collection);
6
+ }
7
+ });
8
+ return subcollections;
9
+ };
@@ -0,0 +1,2 @@
1
+ import type { CollectionField } from "@stoker-platform/types";
2
+ export declare const getSystemFieldsSchema: () => CollectionField[];
@@ -0,0 +1,52 @@
1
+ import { systemFields } from "./system-fields.js";
2
+ export const getSystemFieldsSchema = () => {
3
+ return systemFields.map((field) => {
4
+ let type = "";
5
+ let values;
6
+ switch (field) {
7
+ case "id":
8
+ type = "String";
9
+ break;
10
+ case "Collection_Path":
11
+ type = "Array";
12
+ break;
13
+ case "Created_At":
14
+ type = "Timestamp";
15
+ break;
16
+ case "Saved_At":
17
+ type = "Timestamp";
18
+ break;
19
+ case "Created_By":
20
+ type = "String";
21
+ break;
22
+ case "Last_Write_At":
23
+ type = "Timestamp";
24
+ break;
25
+ case "Last_Save_At":
26
+ type = "Timestamp";
27
+ break;
28
+ case "Last_Write_By":
29
+ type = "String";
30
+ break;
31
+ case "Last_Write_App":
32
+ type = "String";
33
+ break;
34
+ case "Last_Write_Connection_Status":
35
+ type = "String";
36
+ values = ["Online", "Offline"];
37
+ break;
38
+ case "Last_Write_Version":
39
+ type = "Number";
40
+ break;
41
+ }
42
+ const fieldSchema = {
43
+ name: field,
44
+ type: type,
45
+ required: true,
46
+ };
47
+ if (values) {
48
+ fieldSchema.values = values;
49
+ }
50
+ return fieldSchema;
51
+ });
52
+ };
@@ -0,0 +1,2 @@
1
+ import { CollectionField, CollectionSchema, CollectionsSchema } from "@stoker-platform/types";
2
+ export declare const isDependencyField: (mainField: CollectionField, collection: CollectionSchema, schema: CollectionsSchema) => boolean;
@@ -0,0 +1,18 @@
1
+ import { isRelationField } from "./isRelationField.js";
2
+ export const isDependencyField = (mainField, collection, schema) => {
3
+ const collections = Object.values(schema.collections);
4
+ const { labels } = collection;
5
+ let isDependencyField = false;
6
+ for (const collectionSchema of collections) {
7
+ const { fields: dependencyFields } = collectionSchema;
8
+ for (const field of dependencyFields) {
9
+ if (isRelationField(field) && field.collection === labels.collection && field.dependencyFields) {
10
+ for (const dependencyField of field.dependencyFields) {
11
+ if (dependencyField.field == mainField.name)
12
+ isDependencyField = true;
13
+ }
14
+ }
15
+ }
16
+ }
17
+ return isDependencyField;
18
+ };
@@ -0,0 +1,2 @@
1
+ import { CollectionField, CollectionSchema, CollectionsSchema } from "@stoker-platform/types";
2
+ export declare const isIncludedField: (mainField: CollectionField, collection: CollectionSchema, schema: CollectionsSchema) => boolean;
@@ -0,0 +1,18 @@
1
+ import { isRelationField } from "./isRelationField.js";
2
+ export const isIncludedField = (mainField, collection, schema) => {
3
+ const collections = Object.values(schema.collections);
4
+ const { labels } = collection;
5
+ let isIncludedField = false;
6
+ for (const collectionSchema of collections) {
7
+ const { fields: includeFields } = collectionSchema;
8
+ for (const field of includeFields) {
9
+ if (isRelationField(field) && field.collection === labels.collection && field.includeFields) {
10
+ for (const includeField of field.includeFields) {
11
+ if (includeField == mainField.name)
12
+ isIncludedField = true;
13
+ }
14
+ }
15
+ }
16
+ }
17
+ return isIncludedField;
18
+ };
@@ -0,0 +1,2 @@
1
+ import { CollectionField, RelationField } from "@stoker-platform/types";
2
+ export declare const isRelationField: (field: CollectionField) => field is RelationField;
@@ -0,0 +1,3 @@
1
+ export const isRelationField = (field) => {
2
+ return ["OneToOne", "OneToMany", "ManyToOne", "ManyToMany"].includes(field.type);
3
+ };
@@ -0,0 +1,2 @@
1
+ import { SystemField } from "@stoker-platform/types";
2
+ export declare const systemFields: SystemField[];
@@ -0,0 +1,13 @@
1
+ export const systemFields = [
2
+ "id",
3
+ "Collection_Path",
4
+ "Last_Write_At",
5
+ "Last_Save_At",
6
+ "Last_Write_By",
7
+ "Last_Write_App",
8
+ "Last_Write_Connection_Status",
9
+ "Last_Write_Version",
10
+ "Created_At",
11
+ "Saved_At",
12
+ "Created_By",
13
+ ];