@balena/pinejs 21.2.1 → 21.2.2-build-shared-namespace-relationships-6cdf2fab2c3f6796f5543d19d9ecaefbd052c67c-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.
@@ -9,7 +9,6 @@ import type {
9
9
  ReferencedFieldNode,
10
10
  Relationship,
11
11
  RelationshipInternalNode,
12
- RelationshipLeafNode,
13
12
  RelationshipMapping,
14
13
  SelectNode,
15
14
  SelectQueryNode,
@@ -56,6 +55,7 @@ import type { Config } from '../config-loader/config-loader.js';
56
55
  import type { ODataOptions } from 'pinejs-client-core';
57
56
  import type { Permission } from './user.js';
58
57
  import { importSBVR } from '../server-glue/sbvr-loader.js';
58
+ import { namespaceRelationships } from './abstract-sql.js';
59
59
 
60
60
  const userModel = await importSBVR('./user.sbvr', import.meta);
61
61
 
@@ -303,31 +303,6 @@ const collapsePermissionFilters = <T>(
303
303
  return v;
304
304
  };
305
305
 
306
- const namespaceRelationships = (
307
- relationships: Relationship,
308
- alias: string,
309
- ): void => {
310
- for (const [key, relationship] of Object.entries(
311
- relationships as RelationshipInternalNode,
312
- )) {
313
- if (key === '$') {
314
- continue;
315
- }
316
-
317
- let mapping = (relationship as RelationshipLeafNode).$;
318
- if (mapping != null && mapping.length === 2) {
319
- mapping = _.cloneDeep(mapping);
320
- // we do check the length above, but typescript thinks the second
321
- // element could be undefined
322
- mapping[1]![0] = `${mapping[1]![0]}$${alias}`;
323
- (relationships as RelationshipInternalNode)[`${key}$${alias}`] = {
324
- $: mapping,
325
- };
326
- }
327
- namespaceRelationships(relationship, alias);
328
- }
329
- };
330
-
331
306
  type PermissionLookup = Dictionary<true | string[]>;
332
307
 
333
308
  const getPermissionsLookup = env.createCache(
@@ -1174,7 +1149,9 @@ const getBoundConstrainedMemoizer = memoizeWeak(
1174
1149
  for (const relationship of origRelationships) {
1175
1150
  relationships[`${relationship}$${alias}`] =
1176
1151
  relationships[relationship];
1177
- namespaceRelationships(relationships[relationship], alias);
1152
+ namespaceRelationships(relationships[relationship], alias, {
1153
+ deleteOriginal: false,
1154
+ });
1178
1155
  }
1179
1156
  return relationships[permissionResourceName];
1180
1157
  },
@@ -1,13 +1,10 @@
1
1
  import _ from 'lodash';
2
2
  import type {
3
3
  AbstractSqlModel,
4
- Relationship,
5
4
  ReferencedFieldNode,
6
5
  SelectNode,
7
6
  AliasNode,
8
7
  Definition,
9
- RelationshipInternalNode,
10
- RelationshipLeafNode,
11
8
  SelectQueryNode,
12
9
  NumberTypeNodes,
13
10
  BooleanTypeNodes,
@@ -15,6 +12,7 @@ import type {
15
12
  NullNode,
16
13
  } from '@balena/abstract-sql-compiler';
17
14
  import type { Dictionary } from './common-types.js';
15
+ import { namespaceRelationships as $namespaceRelationships } from './abstract-sql.js';
18
16
 
19
17
  export type AliasValidNodeType =
20
18
  | ReferencedFieldNode
@@ -95,29 +93,13 @@ const aliasResource = (
95
93
  };
96
94
 
97
95
  const namespaceRelationships = (
98
- relationships: Relationship,
99
- alias: string,
96
+ relationships: Parameters<typeof $namespaceRelationships>[0],
97
+ alias: Parameters<typeof $namespaceRelationships>[1],
100
98
  ): void => {
101
- for (const [key, relationship] of Object.entries(
102
- relationships as RelationshipInternalNode,
103
- )) {
104
- if (key === '$') {
105
- continue;
106
- }
107
-
108
- let mapping = (relationship as RelationshipLeafNode).$;
109
- if (mapping != null && mapping.length === 2) {
110
- if (!key.includes('$')) {
111
- mapping = _.cloneDeep(mapping);
112
- mapping[1]![0] = `${mapping[1]![0]}$${alias}`;
113
- (relationships as RelationshipInternalNode)[`${key}$${alias}`] = {
114
- $: mapping,
115
- };
116
- delete (relationships as RelationshipInternalNode)[key];
117
- }
118
- }
119
- namespaceRelationships(relationship, alias);
120
- }
99
+ $namespaceRelationships(relationships, alias, {
100
+ keyFilter: (key) => !key.includes('$'),
101
+ deleteOriginal: true,
102
+ });
121
103
  };
122
104
 
123
105
  export const translateAbstractSqlModel = (