mirror of
https://github.com/lowdefy/lowdefy.git
synced 2025-01-18 13:34:56 +08:00
feat: Add _uuid operator to NodeParser.
This commit is contained in:
parent
41d19608b4
commit
0f562feff5
3
.pnp.js
generated
3
.pnp.js
generated
@ -4660,7 +4660,8 @@ function $$SETUP_STATE(hydrateRuntimeState, basePath) {
|
|||||||
["babel-jest", "virtual:caddf51df4928b33a437ca87b8f5ddfb6205ebd6d8231f74d4ee7223f3866e6f815b221aa1e2bd33e98915f701e95bae72a93d2288b49a34a6246bdbc2a4a132#npm:26.6.3"],
|
["babel-jest", "virtual:caddf51df4928b33a437ca87b8f5ddfb6205ebd6d8231f74d4ee7223f3866e6f815b221aa1e2bd33e98915f701e95bae72a93d2288b49a34a6246bdbc2a4a132#npm:26.6.3"],
|
||||||
["jest", "npm:26.6.3"],
|
["jest", "npm:26.6.3"],
|
||||||
["js-yaml", "npm:3.14.1"],
|
["js-yaml", "npm:3.14.1"],
|
||||||
["mingo", "npm:3.1.0"]
|
["mingo", "npm:3.1.0"],
|
||||||
|
["uuid", "npm:8.3.2"]
|
||||||
],
|
],
|
||||||
"linkType": "SOFT",
|
"linkType": "SOFT",
|
||||||
}]
|
}]
|
||||||
|
@ -41,7 +41,8 @@
|
|||||||
"@lowdefy/helpers": "3.1.1",
|
"@lowdefy/helpers": "3.1.1",
|
||||||
"@lowdefy/nunjucks": "3.1.1",
|
"@lowdefy/nunjucks": "3.1.1",
|
||||||
"js-yaml": "3.14.1",
|
"js-yaml": "3.14.1",
|
||||||
"mingo": "3.1.0"
|
"mingo": "3.1.0",
|
||||||
|
"uuid": "8.3.2"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@babel/cli": "7.12.10",
|
"@babel/cli": "7.12.10",
|
||||||
|
@ -17,9 +17,11 @@
|
|||||||
import _secret from './secret';
|
import _secret from './secret';
|
||||||
import _base64_decode from './base64_decode';
|
import _base64_decode from './base64_decode';
|
||||||
import _base64_encode from './base64_encode';
|
import _base64_encode from './base64_encode';
|
||||||
|
import _uuid from './uuid';
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
_base64_decode,
|
_base64_decode,
|
||||||
_base64_encode,
|
_base64_encode,
|
||||||
_secret,
|
_secret,
|
||||||
|
_uuid,
|
||||||
};
|
};
|
||||||
|
23
packages/operators/src/node/uuid.js
Normal file
23
packages/operators/src/node/uuid.js
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
/*
|
||||||
|
Copyright 2020 Lowdefy, Inc
|
||||||
|
|
||||||
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
you may not use this file except in compliance with the License.
|
||||||
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
import { v4 as uuidv4 } from 'uuid';
|
||||||
|
|
||||||
|
function _uuid() {
|
||||||
|
return uuidv4();
|
||||||
|
}
|
||||||
|
|
||||||
|
export default _uuid;
|
@ -190,3 +190,11 @@ test('parse _random operator', () => {
|
|||||||
expect(res.errors).toMatchInlineSnapshot(`Array []`);
|
expect(res.errors).toMatchInlineSnapshot(`Array []`);
|
||||||
Math.random = mathRandomFn;
|
Math.random = mathRandomFn;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('parse _uuid operator', () => {
|
||||||
|
const input = { a: { _uuid: true } };
|
||||||
|
const parser = new NodeParser({ state });
|
||||||
|
const res = parser.parse({ input, args, location: 'locationId' });
|
||||||
|
expect(res.output.a.length).toEqual(36);
|
||||||
|
expect(res.errors).toMatchInlineSnapshot(`Array []`);
|
||||||
|
});
|
||||||
|
13
packages/operators/test/node/uuid.test.js
Normal file
13
packages/operators/test/node/uuid.test.js
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
import { v4 as uuidv4 } from 'uuid';
|
||||||
|
import uuid from '../../src/node/uuid';
|
||||||
|
|
||||||
|
jest.mock('uuid', () => {
|
||||||
|
return {
|
||||||
|
v4: jest.fn(() => 'ABC'),
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
|
test('_uuid', () => {
|
||||||
|
expect(uuid({ params: true, location: 'locationId' })).toEqual('ABC');
|
||||||
|
expect(uuidv4).toHaveBeenCalled();
|
||||||
|
});
|
@ -30,12 +30,6 @@ const context = {
|
|||||||
menuId: 'm_2',
|
menuId: 'm_2',
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
mutations: {
|
|
||||||
not_loaded: { loading: true, response: 'fail' },
|
|
||||||
string: { loading: false, response: 'mutation String' },
|
|
||||||
number: { loading: false, response: 500 },
|
|
||||||
arr: { loading: false, response: [{ a: 'mutation a1' }, { a: 'mutation a2' }] },
|
|
||||||
},
|
|
||||||
requests: {
|
requests: {
|
||||||
not_loaded: { loading: true, response: 'fail' },
|
not_loaded: { loading: true, response: 'fail' },
|
||||||
string: { loading: false, response: 'request String' },
|
string: { loading: false, response: 'request String' },
|
||||||
|
Loading…
Reference in New Issue
Block a user