@expo/entity-codemod 0.40.0 → 0.41.0
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.
- package/LICENSE +21 -0
- package/build/transforms/__tests__/v0.40.0-v0.41.0-test.d.ts +1 -0
- package/build/transforms/__tests__/v0.40.0-v0.41.0-test.js +16 -0
- package/build/transforms/__tests__/v0.40.0-v0.41.0-test.js.map +1 -0
- package/build/transforms/v0.40.0-v0.41.0.d.ts +2 -0
- package/build/transforms/v0.40.0-v0.41.0.js +70 -0
- package/build/transforms/v0.40.0-v0.41.0.js.map +1 -0
- package/package.json +3 -2
- package/src/transforms/__testfixtures__/v0.40.0-v0.41.0/test1.input.ts +100 -0
- package/src/transforms/__testfixtures__/v0.40.0-v0.41.0/test1.output.ts +100 -0
- package/src/transforms/__tests__/v0.40.0-v0.41.0-test.ts +16 -0
- package/src/transforms/v0.40.0-v0.41.0.ts +81 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2020-present 650 Industries, Inc. (aka Expo)
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const fs_1 = require("fs");
|
|
4
|
+
const path_1 = require("path");
|
|
5
|
+
jest.autoMockOff();
|
|
6
|
+
const defineTest = require('jscodeshift/dist/testUtils').defineTest;
|
|
7
|
+
const fixtureDir = 'v0.40.0-v0.41.0';
|
|
8
|
+
const fixtureDirPath = (0, path_1.join)(__dirname, '..', '__testfixtures__', fixtureDir);
|
|
9
|
+
const fixtures = (0, fs_1.readdirSync)(fixtureDirPath)
|
|
10
|
+
.filter((file) => file.endsWith('.input.ts'))
|
|
11
|
+
.map((file) => file.replace('.input.ts', ''));
|
|
12
|
+
for (const fixture of fixtures) {
|
|
13
|
+
const prefix = `${fixtureDir}/${fixture}`;
|
|
14
|
+
defineTest(__dirname, 'v0.40.0-v0.41.0', null, prefix, { parser: 'ts' });
|
|
15
|
+
}
|
|
16
|
+
//# sourceMappingURL=v0.40.0-v0.41.0-test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"v0.40.0-v0.41.0-test.js","sourceRoot":"","sources":["../../../src/transforms/__tests__/v0.40.0-v0.41.0-test.ts"],"names":[],"mappings":";;AAAA,2BAAiC;AACjC,+BAA4B;AAE5B,IAAI,CAAC,WAAW,EAAE,CAAC;AACnB,MAAM,UAAU,GAAG,OAAO,CAAC,4BAA4B,CAAC,CAAC,UAAU,CAAC;AAEpE,MAAM,UAAU,GAAG,iBAAiB,CAAC;AACrC,MAAM,cAAc,GAAG,IAAA,WAAI,EAAC,SAAS,EAAE,IAAI,EAAE,kBAAkB,EAAE,UAAU,CAAC,CAAC;AAC7E,MAAM,QAAQ,GAAG,IAAA,gBAAW,EAAC,cAAc,CAAC;KACzC,MAAM,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,QAAQ,CAAC,WAAW,CAAC,CAAC;KAC5C,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,OAAO,CAAC,WAAW,EAAE,EAAE,CAAC,CAAC,CAAC;AAEhD,KAAK,MAAM,OAAO,IAAI,QAAQ,EAAE,CAAC;IAC/B,MAAM,MAAM,GAAG,GAAG,UAAU,IAAI,OAAO,EAAE,CAAC;IAC1C,UAAU,CAAC,SAAS,EAAE,iBAAiB,EAAE,IAAI,EAAE,MAAM,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC,CAAC;AAC3E,CAAC"}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.default = transformer;
|
|
4
|
+
function transformWithAuthorizationResultsEntityChainMethod(j, root) {
|
|
5
|
+
// Find all entity expressions of the form
|
|
6
|
+
// `TestEntity.thing(viewerContext).withAuthorizationResults()`
|
|
7
|
+
root
|
|
8
|
+
.find(j.CallExpression, {
|
|
9
|
+
callee: {
|
|
10
|
+
type: 'MemberExpression',
|
|
11
|
+
property: {
|
|
12
|
+
name: 'withAuthorizationResults',
|
|
13
|
+
},
|
|
14
|
+
},
|
|
15
|
+
})
|
|
16
|
+
.forEach((path) => {
|
|
17
|
+
const withAuthorizationResultsCallExpression = path.node; // TestEntity.thing(viewerContext).withAuthorizationResults()
|
|
18
|
+
const withAuthorizationResultsCallee = withAuthorizationResultsCallExpression.callee; // TestEntity.thing(viewerContext).withAuthorizationResults
|
|
19
|
+
if (withAuthorizationResultsCallee.type !== 'MemberExpression') {
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
const thingCallExpression = withAuthorizationResultsCallee.object; // TestEntity.thing(viewerContext)
|
|
23
|
+
if (thingCallExpression.type !== 'CallExpression') {
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
const thingCallee = thingCallExpression.callee; // TestEntity.thing
|
|
27
|
+
if (thingCallee.type !== 'MemberExpression') {
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
if (thingCallee.property.type !== 'Identifier') {
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
const newCreatorCalleeName = thingCallee.property.name + 'WithAuthorizationResults';
|
|
34
|
+
thingCallee.property.name = newCreatorCalleeName;
|
|
35
|
+
path.replace(thingCallExpression);
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
function transformEnforcingEntityChainMethod(j, root) {
|
|
39
|
+
// Find all entity expressions of the form
|
|
40
|
+
// `TestEntity.thing(viewerContext).enforcing()`
|
|
41
|
+
root
|
|
42
|
+
.find(j.CallExpression, {
|
|
43
|
+
callee: {
|
|
44
|
+
type: 'MemberExpression',
|
|
45
|
+
property: {
|
|
46
|
+
name: 'enforcing',
|
|
47
|
+
},
|
|
48
|
+
},
|
|
49
|
+
})
|
|
50
|
+
.forEach((path) => {
|
|
51
|
+
const enforcingCallExpression = path.node; // TestEntity.thing(viewerContext).enforcing()
|
|
52
|
+
const enforcingCallee = enforcingCallExpression.callee; // TestEntity.thing(viewerContext).enforcing
|
|
53
|
+
if (enforcingCallee.type !== 'MemberExpression') {
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
const thingCallExpression = enforcingCallee.object; // TestEntity.thing(viewerContext)
|
|
57
|
+
if (thingCallExpression.type !== 'CallExpression') {
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
path.replace(thingCallExpression);
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
function transformer(file, api, _options) {
|
|
64
|
+
const j = api.jscodeshift;
|
|
65
|
+
const root = j.withParser('ts')(file.source);
|
|
66
|
+
transformWithAuthorizationResultsEntityChainMethod(j, root);
|
|
67
|
+
transformEnforcingEntityChainMethod(j, root);
|
|
68
|
+
return root.toSource();
|
|
69
|
+
}
|
|
70
|
+
//# sourceMappingURL=v0.40.0-v0.41.0.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"v0.40.0-v0.41.0.js","sourceRoot":"","sources":["../../src/transforms/v0.40.0-v0.41.0.ts"],"names":[],"mappings":";;AAwEA,8BAQC;AA9ED,SAAS,kDAAkD,CACzD,CAAqB,EACrB,IAAqB;IAErB,0CAA0C;IAC1C,+DAA+D;IAC/D,IAAI;SACD,IAAI,CAAC,CAAC,CAAC,cAAc,EAAE;QACtB,MAAM,EAAE;YACN,IAAI,EAAE,kBAAkB;YACxB,QAAQ,EAAE;gBACR,IAAI,EAAE,0BAA0B;aACjC;SACF;KACF,CAAC;SACD,OAAO,CAAC,CAAC,IAAI,EAAE,EAAE;QAChB,MAAM,sCAAsC,GAAG,IAAI,CAAC,IAAI,CAAC,CAAC,6DAA6D;QACvH,MAAM,8BAA8B,GAAG,sCAAsC,CAAC,MAAM,CAAC,CAAC,2DAA2D;QACjJ,IAAI,8BAA8B,CAAC,IAAI,KAAK,kBAAkB,EAAE,CAAC;YAC/D,OAAO;QACT,CAAC;QAED,MAAM,mBAAmB,GAAG,8BAA8B,CAAC,MAAM,CAAC,CAAC,kCAAkC;QACrG,IAAI,mBAAmB,CAAC,IAAI,KAAK,gBAAgB,EAAE,CAAC;YAClD,OAAO;QACT,CAAC;QACD,MAAM,WAAW,GAAG,mBAAmB,CAAC,MAAM,CAAC,CAAC,mBAAmB;QACnE,IAAI,WAAW,CAAC,IAAI,KAAK,kBAAkB,EAAE,CAAC;YAC5C,OAAO;QACT,CAAC;QAED,IAAI,WAAW,CAAC,QAAQ,CAAC,IAAI,KAAK,YAAY,EAAE,CAAC;YAC/C,OAAO;QACT,CAAC;QAED,MAAM,oBAAoB,GAAG,WAAW,CAAC,QAAQ,CAAC,IAAI,GAAG,0BAA0B,CAAC;QACpF,WAAW,CAAC,QAAQ,CAAC,IAAI,GAAG,oBAAoB,CAAC;QAEjD,IAAI,CAAC,OAAO,CAAC,mBAAmB,CAAC,CAAC;IACpC,CAAC,CAAC,CAAC;AACP,CAAC;AAED,SAAS,mCAAmC,CAAC,CAAqB,EAAE,IAAqB;IACvF,0CAA0C;IAC1C,gDAAgD;IAChD,IAAI;SACD,IAAI,CAAC,CAAC,CAAC,cAAc,EAAE;QACtB,MAAM,EAAE;YACN,IAAI,EAAE,kBAAkB;YACxB,QAAQ,EAAE;gBACR,IAAI,EAAE,WAAW;aAClB;SACF;KACF,CAAC;SACD,OAAO,CAAC,CAAC,IAAI,EAAE,EAAE;QAChB,MAAM,uBAAuB,GAAG,IAAI,CAAC,IAAI,CAAC,CAAC,8CAA8C;QACzF,MAAM,eAAe,GAAG,uBAAuB,CAAC,MAAM,CAAC,CAAC,4CAA4C;QACpG,IAAI,eAAe,CAAC,IAAI,KAAK,kBAAkB,EAAE,CAAC;YAChD,OAAO;QACT,CAAC;QAED,MAAM,mBAAmB,GAAG,eAAe,CAAC,MAAM,CAAC,CAAC,kCAAkC;QACtF,IAAI,mBAAmB,CAAC,IAAI,KAAK,gBAAgB,EAAE,CAAC;YAClD,OAAO;QACT,CAAC;QAED,IAAI,CAAC,OAAO,CAAC,mBAAmB,CAAC,CAAC;IACpC,CAAC,CAAC,CAAC;AACP,CAAC;AAED,SAAwB,WAAW,CAAC,IAAc,EAAE,GAAQ,EAAE,QAAiB;IAC7E,MAAM,CAAC,GAAG,GAAG,CAAC,WAAW,CAAC;IAC1B,MAAM,IAAI,GAAG,CAAC,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;IAE7C,kDAAkD,CAAC,CAAC,EAAE,IAAI,CAAC,CAAC;IAC5D,mCAAmC,CAAC,CAAC,EAAE,IAAI,CAAC,CAAC;IAE7C,OAAO,IAAI,CAAC,QAAQ,EAAE,CAAC;AACzB,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@expo/entity-codemod",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.41.0",
|
|
4
4
|
"description": "jscodeshift codemods for @expo/entity upgrades",
|
|
5
5
|
"files": [
|
|
6
6
|
"build",
|
|
@@ -36,5 +36,6 @@
|
|
|
36
36
|
"ts-jest": "^29.2.5",
|
|
37
37
|
"ts-mockito": "^2.6.1",
|
|
38
38
|
"typescript": "^5.7.3"
|
|
39
|
-
}
|
|
39
|
+
},
|
|
40
|
+
"gitHead": "ee4be736a9a0ba580e9af0194e07c9cd36b1c599"
|
|
40
41
|
}
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
/* eslint-disable */
|
|
2
|
+
|
|
3
|
+
import { ViewerContext } from '@expo/entity';
|
|
4
|
+
|
|
5
|
+
async function testWithAuthorizationResults(viewerContext: ViewerContext): Promise<void> {
|
|
6
|
+
// creator
|
|
7
|
+
const entityResult = await TestEntity.creator(viewerContext).withAuthorizationResults().setField('wat', 2).createAsync();
|
|
8
|
+
|
|
9
|
+
// updater
|
|
10
|
+
const updatedEntityResult = await TestEntity.updater(entityResult.enforceValue()).withAuthorizationResults().setField('wat', 3).updateAsync();
|
|
11
|
+
|
|
12
|
+
// loader
|
|
13
|
+
const loadedEntityResult = await TestEntity.loader(viewerContext).withAuthorizationResults().loadByIDAsync('test');
|
|
14
|
+
|
|
15
|
+
// deleter
|
|
16
|
+
await TestEntity.deleter(updatedEntityResult.enforceValue()).withAuthorizationResults().deleteAsync();
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
async function testEnforcing(viewerContext: ViewerContext): Promise<void> {
|
|
20
|
+
// creator
|
|
21
|
+
const entity = await TestEntity.creator(viewerContext).enforcing().setField('wat', 2).createAsync();
|
|
22
|
+
const entity2 = await TestEntity.creator(viewerContext).enforcing().setField('wat', 2).setField('who', 3).createAsync();
|
|
23
|
+
const entity3 = await TestEntity.creator(viewerContext).enforcing()
|
|
24
|
+
.setField('wat', 2)
|
|
25
|
+
.setField('who', 3)
|
|
26
|
+
.setField('who', 4)
|
|
27
|
+
.setField('who', 5)
|
|
28
|
+
.setField('who', 6)
|
|
29
|
+
.setField('who', 7)
|
|
30
|
+
.setField('who', 8)
|
|
31
|
+
.setField('who', 9)
|
|
32
|
+
.createAsync();
|
|
33
|
+
|
|
34
|
+
// updater
|
|
35
|
+
const updatedEntity = await TestEntity.updater(entity).enforcing().setField('wat', 3).updateAsync();
|
|
36
|
+
const updatedEntity2 = await TestEntity.updater(entity2).enforcing().setField('wat', 3).setField('who', 4).updateAsync();
|
|
37
|
+
const updatedEntity3 = await TestEntity.updater(entity3).enforcing()
|
|
38
|
+
.setField('wat', 3)
|
|
39
|
+
.setField('who', 4)
|
|
40
|
+
.setField('who', 5)
|
|
41
|
+
.setField('who', 6)
|
|
42
|
+
.setField('who', 7)
|
|
43
|
+
.setField('who', 8)
|
|
44
|
+
.setField('who', 9)
|
|
45
|
+
.updateAsync();
|
|
46
|
+
|
|
47
|
+
// loader
|
|
48
|
+
const loadedEntity = await TestEntity.loader(viewerContext).enforcing().loadByIDAsync('test');
|
|
49
|
+
|
|
50
|
+
// deleter
|
|
51
|
+
await TestEntity.deleter(entity).enforcing().deleteAsync();
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
async function testNoSetField(viewerContext: ViewerContext): Promise<void> {
|
|
55
|
+
// creator
|
|
56
|
+
const entity = await TestEntity.creator(viewerContext).enforcing().createAsync();
|
|
57
|
+
|
|
58
|
+
// updater
|
|
59
|
+
const updatedEntity = await TestEntity.updater(entity).enforcing().updateAsync();
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
async function testEnforcingWithQueryContext(viewerContext: ViewerContext): Promise<void> {
|
|
63
|
+
// creator
|
|
64
|
+
const entity = await TestEntity.creator(viewerContext, queryContext).enforcing().setField('wat', 2).createAsync();
|
|
65
|
+
|
|
66
|
+
// updater
|
|
67
|
+
const updatedEntity = await TestEntity.updater(entity, queryContext).enforcing().setField('wat', 3).updateAsync();
|
|
68
|
+
|
|
69
|
+
// loader
|
|
70
|
+
const loadedEntity = await TestEntity.loader(viewerContext, queryContext).enforcing().loadByIDAsync('test');
|
|
71
|
+
|
|
72
|
+
// deleter
|
|
73
|
+
await TestEntity.deleter(entity, queryContext).enforcing().deleteAsync();
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
async function testAssociationLoader(): Promise<void> {
|
|
77
|
+
await this.associationLoader().withAuthorizationResults().loadAssociatedEntityAsync(
|
|
78
|
+
'another_id',
|
|
79
|
+
AnotherEntity,
|
|
80
|
+
queryContext
|
|
81
|
+
);
|
|
82
|
+
|
|
83
|
+
await entity.associationLoader().withAuthorizationResults().loadAssociatedEntityAsync(
|
|
84
|
+
'another_id',
|
|
85
|
+
AnotherEntity,
|
|
86
|
+
queryContext
|
|
87
|
+
)
|
|
88
|
+
|
|
89
|
+
await this.associationLoader().enforcing().loadAssociatedEntityAsync(
|
|
90
|
+
'another_id',
|
|
91
|
+
AnotherEntity,
|
|
92
|
+
queryContext
|
|
93
|
+
);
|
|
94
|
+
|
|
95
|
+
await entity.associationLoader().enforcing().loadAssociatedEntityAsync(
|
|
96
|
+
'another_id',
|
|
97
|
+
AnotherEntity,
|
|
98
|
+
queryContext
|
|
99
|
+
)
|
|
100
|
+
}
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
/* eslint-disable */
|
|
2
|
+
|
|
3
|
+
import { ViewerContext } from '@expo/entity';
|
|
4
|
+
|
|
5
|
+
async function testWithAuthorizationResults(viewerContext: ViewerContext): Promise<void> {
|
|
6
|
+
// creator
|
|
7
|
+
const entityResult = await TestEntity.creatorWithAuthorizationResults(viewerContext).setField('wat', 2).createAsync();
|
|
8
|
+
|
|
9
|
+
// updater
|
|
10
|
+
const updatedEntityResult = await TestEntity.updaterWithAuthorizationResults(entityResult.enforceValue()).setField('wat', 3).updateAsync();
|
|
11
|
+
|
|
12
|
+
// loader
|
|
13
|
+
const loadedEntityResult = await TestEntity.loaderWithAuthorizationResults(viewerContext).loadByIDAsync('test');
|
|
14
|
+
|
|
15
|
+
// deleter
|
|
16
|
+
await TestEntity.deleterWithAuthorizationResults(updatedEntityResult.enforceValue()).deleteAsync();
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
async function testEnforcing(viewerContext: ViewerContext): Promise<void> {
|
|
20
|
+
// creator
|
|
21
|
+
const entity = await TestEntity.creator(viewerContext).setField('wat', 2).createAsync();
|
|
22
|
+
const entity2 = await TestEntity.creator(viewerContext).setField('wat', 2).setField('who', 3).createAsync();
|
|
23
|
+
const entity3 = await TestEntity.creator(viewerContext)
|
|
24
|
+
.setField('wat', 2)
|
|
25
|
+
.setField('who', 3)
|
|
26
|
+
.setField('who', 4)
|
|
27
|
+
.setField('who', 5)
|
|
28
|
+
.setField('who', 6)
|
|
29
|
+
.setField('who', 7)
|
|
30
|
+
.setField('who', 8)
|
|
31
|
+
.setField('who', 9)
|
|
32
|
+
.createAsync();
|
|
33
|
+
|
|
34
|
+
// updater
|
|
35
|
+
const updatedEntity = await TestEntity.updater(entity).setField('wat', 3).updateAsync();
|
|
36
|
+
const updatedEntity2 = await TestEntity.updater(entity2).setField('wat', 3).setField('who', 4).updateAsync();
|
|
37
|
+
const updatedEntity3 = await TestEntity.updater(entity3)
|
|
38
|
+
.setField('wat', 3)
|
|
39
|
+
.setField('who', 4)
|
|
40
|
+
.setField('who', 5)
|
|
41
|
+
.setField('who', 6)
|
|
42
|
+
.setField('who', 7)
|
|
43
|
+
.setField('who', 8)
|
|
44
|
+
.setField('who', 9)
|
|
45
|
+
.updateAsync();
|
|
46
|
+
|
|
47
|
+
// loader
|
|
48
|
+
const loadedEntity = await TestEntity.loader(viewerContext).loadByIDAsync('test');
|
|
49
|
+
|
|
50
|
+
// deleter
|
|
51
|
+
await TestEntity.deleter(entity).deleteAsync();
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
async function testNoSetField(viewerContext: ViewerContext): Promise<void> {
|
|
55
|
+
// creator
|
|
56
|
+
const entity = await TestEntity.creator(viewerContext).createAsync();
|
|
57
|
+
|
|
58
|
+
// updater
|
|
59
|
+
const updatedEntity = await TestEntity.updater(entity).updateAsync();
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
async function testEnforcingWithQueryContext(viewerContext: ViewerContext): Promise<void> {
|
|
63
|
+
// creator
|
|
64
|
+
const entity = await TestEntity.creator(viewerContext, queryContext).setField('wat', 2).createAsync();
|
|
65
|
+
|
|
66
|
+
// updater
|
|
67
|
+
const updatedEntity = await TestEntity.updater(entity, queryContext).setField('wat', 3).updateAsync();
|
|
68
|
+
|
|
69
|
+
// loader
|
|
70
|
+
const loadedEntity = await TestEntity.loader(viewerContext, queryContext).loadByIDAsync('test');
|
|
71
|
+
|
|
72
|
+
// deleter
|
|
73
|
+
await TestEntity.deleter(entity, queryContext).deleteAsync();
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
async function testAssociationLoader(): Promise<void> {
|
|
77
|
+
await this.associationLoaderWithAuthorizationResults().loadAssociatedEntityAsync(
|
|
78
|
+
'another_id',
|
|
79
|
+
AnotherEntity,
|
|
80
|
+
queryContext
|
|
81
|
+
);
|
|
82
|
+
|
|
83
|
+
await entity.associationLoaderWithAuthorizationResults().loadAssociatedEntityAsync(
|
|
84
|
+
'another_id',
|
|
85
|
+
AnotherEntity,
|
|
86
|
+
queryContext
|
|
87
|
+
)
|
|
88
|
+
|
|
89
|
+
await this.associationLoader().loadAssociatedEntityAsync(
|
|
90
|
+
'another_id',
|
|
91
|
+
AnotherEntity,
|
|
92
|
+
queryContext
|
|
93
|
+
);
|
|
94
|
+
|
|
95
|
+
await entity.associationLoader().loadAssociatedEntityAsync(
|
|
96
|
+
'another_id',
|
|
97
|
+
AnotherEntity,
|
|
98
|
+
queryContext
|
|
99
|
+
)
|
|
100
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { readdirSync } from 'fs';
|
|
2
|
+
import { join } from 'path';
|
|
3
|
+
|
|
4
|
+
jest.autoMockOff();
|
|
5
|
+
const defineTest = require('jscodeshift/dist/testUtils').defineTest;
|
|
6
|
+
|
|
7
|
+
const fixtureDir = 'v0.40.0-v0.41.0';
|
|
8
|
+
const fixtureDirPath = join(__dirname, '..', '__testfixtures__', fixtureDir);
|
|
9
|
+
const fixtures = readdirSync(fixtureDirPath)
|
|
10
|
+
.filter((file) => file.endsWith('.input.ts'))
|
|
11
|
+
.map((file) => file.replace('.input.ts', ''));
|
|
12
|
+
|
|
13
|
+
for (const fixture of fixtures) {
|
|
14
|
+
const prefix = `${fixtureDir}/${fixture}`;
|
|
15
|
+
defineTest(__dirname, 'v0.40.0-v0.41.0', null, prefix, { parser: 'ts' });
|
|
16
|
+
}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { API, Collection, FileInfo, Options } from 'jscodeshift';
|
|
2
|
+
|
|
3
|
+
function transformWithAuthorizationResultsEntityChainMethod(
|
|
4
|
+
j: API['jscodeshift'],
|
|
5
|
+
root: Collection<any>,
|
|
6
|
+
): void {
|
|
7
|
+
// Find all entity expressions of the form
|
|
8
|
+
// `TestEntity.thing(viewerContext).withAuthorizationResults()`
|
|
9
|
+
root
|
|
10
|
+
.find(j.CallExpression, {
|
|
11
|
+
callee: {
|
|
12
|
+
type: 'MemberExpression',
|
|
13
|
+
property: {
|
|
14
|
+
name: 'withAuthorizationResults',
|
|
15
|
+
},
|
|
16
|
+
},
|
|
17
|
+
})
|
|
18
|
+
.forEach((path) => {
|
|
19
|
+
const withAuthorizationResultsCallExpression = path.node; // TestEntity.thing(viewerContext).withAuthorizationResults()
|
|
20
|
+
const withAuthorizationResultsCallee = withAuthorizationResultsCallExpression.callee; // TestEntity.thing(viewerContext).withAuthorizationResults
|
|
21
|
+
if (withAuthorizationResultsCallee.type !== 'MemberExpression') {
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
const thingCallExpression = withAuthorizationResultsCallee.object; // TestEntity.thing(viewerContext)
|
|
26
|
+
if (thingCallExpression.type !== 'CallExpression') {
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
const thingCallee = thingCallExpression.callee; // TestEntity.thing
|
|
30
|
+
if (thingCallee.type !== 'MemberExpression') {
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
if (thingCallee.property.type !== 'Identifier') {
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
const newCreatorCalleeName = thingCallee.property.name + 'WithAuthorizationResults';
|
|
39
|
+
thingCallee.property.name = newCreatorCalleeName;
|
|
40
|
+
|
|
41
|
+
path.replace(thingCallExpression);
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
function transformEnforcingEntityChainMethod(j: API['jscodeshift'], root: Collection<any>): void {
|
|
46
|
+
// Find all entity expressions of the form
|
|
47
|
+
// `TestEntity.thing(viewerContext).enforcing()`
|
|
48
|
+
root
|
|
49
|
+
.find(j.CallExpression, {
|
|
50
|
+
callee: {
|
|
51
|
+
type: 'MemberExpression',
|
|
52
|
+
property: {
|
|
53
|
+
name: 'enforcing',
|
|
54
|
+
},
|
|
55
|
+
},
|
|
56
|
+
})
|
|
57
|
+
.forEach((path) => {
|
|
58
|
+
const enforcingCallExpression = path.node; // TestEntity.thing(viewerContext).enforcing()
|
|
59
|
+
const enforcingCallee = enforcingCallExpression.callee; // TestEntity.thing(viewerContext).enforcing
|
|
60
|
+
if (enforcingCallee.type !== 'MemberExpression') {
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
const thingCallExpression = enforcingCallee.object; // TestEntity.thing(viewerContext)
|
|
65
|
+
if (thingCallExpression.type !== 'CallExpression') {
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
path.replace(thingCallExpression);
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
export default function transformer(file: FileInfo, api: API, _options: Options): string {
|
|
74
|
+
const j = api.jscodeshift;
|
|
75
|
+
const root = j.withParser('ts')(file.source);
|
|
76
|
+
|
|
77
|
+
transformWithAuthorizationResultsEntityChainMethod(j, root);
|
|
78
|
+
transformEnforcingEntityChainMethod(j, root);
|
|
79
|
+
|
|
80
|
+
return root.toSource();
|
|
81
|
+
}
|