@laboratoria/sdk-js 1.2.0 → 1.5.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/index.js CHANGED
@@ -59,5 +59,6 @@ export const createApp = ({
59
59
  ...curriculumAPI,
60
60
  ...coreAPI,
61
61
  auth: authAPI,
62
+ firebaseApp,
62
63
  };
63
64
  };
package/lib/core.js CHANGED
@@ -14,6 +14,7 @@ const extended = {
14
14
  'firstName',
15
15
  'lastName',
16
16
  'email',
17
+ 'password',
17
18
  'lang',
18
19
  'github',
19
20
  'linkedin',
@@ -123,15 +124,20 @@ const extended = {
123
124
  inputProps: [
124
125
  'user',
125
126
  'country',
126
- 'currency',
127
127
  'isEmployment',
128
- 'feeBasis',
129
128
  'feeAmount',
130
129
  'hoursPerWeek',
131
130
  'start',
132
131
  'end',
132
+ 'isTrial',
133
+ 'checkPilot',
134
+ 'source',
135
+ ],
136
+ searchProps: [
137
+ 'user.firstName',
138
+ 'user.lastName',
139
+ 'user.email',
133
140
  ],
134
- searchProps: ['user.firstName'],
135
141
  getOptionLabel: ({ id, user }) => `${user?.firstName} (id: ${id})`,
136
142
  },
137
143
  Gig: {
package/lib/model.js CHANGED
@@ -15,10 +15,10 @@ const isOptionalOneToOneRelation = (schema, key) => (
15
15
  && schema.properties[key].anyOf[1]?.type === 'null'
16
16
  );
17
17
 
18
- const isOneToOneRelation = (schema, key) => (
19
- isRequiredOneToOneRelation(schema, key)
20
- || isOptionalOneToOneRelation(schema, key)
21
- );
18
+ // const isOneToOneRelation = (schema, key) => (
19
+ // isRequiredOneToOneRelation(schema, key)
20
+ // || isOptionalOneToOneRelation(schema, key)
21
+ // );
22
22
 
23
23
  const isOneToManyRelation = (schema, key) => (
24
24
  schema.properties
@@ -123,7 +123,7 @@ const serializeData = (data, schema) => {
123
123
  };
124
124
 
125
125
 
126
- export const createModel = (baseUrl, state, collectionName, schema = {}) => {
126
+ export const createModel = (baseUrl, state, collectionName, schema = {}, models = {}) => {
127
127
  const primaryKey = schema.primaryKey || 'id';
128
128
  const validator = createValidator(schema);
129
129
  const buildURL = createBuildURL(collectionName);
@@ -141,9 +141,40 @@ export const createModel = (baseUrl, state, collectionName, schema = {}) => {
141
141
  };
142
142
 
143
143
  const parse = data => {
144
+ if (!data) {
145
+ return data;
146
+ }
147
+
144
148
  const parsed = Object.keys(data).reduce(
145
149
  (memo, key) => {
146
- const { type, format } = schema.properties[key] || {};
150
+ const propSchema = schema.properties[key] || {};
151
+ const { type, format, items } = propSchema;
152
+ if (items && isOneToManyRelation(schema, key)) {
153
+ const relationModelName = items.$ref.split('/').pop().toLowerCase();
154
+ return {
155
+ ...memo,
156
+ [key]: (
157
+ typeof models[relationModelName]?.parse === 'function'
158
+ ? data[key].map(obj => models[relationModelName].parse(obj))
159
+ : data[key]
160
+ ),
161
+ };
162
+ }
163
+ const ref = (
164
+ isRequiredOneToOneRelation(schema, key)
165
+ ? propSchema.$ref
166
+ : isOptionalOneToOneRelation(schema, key)
167
+ ? propSchema.anyOf[0]?.$ref
168
+ : null
169
+ );
170
+
171
+ if (ref) {
172
+ const relationModelName = ref.split('/').pop().toLowerCase();
173
+ return {
174
+ ...memo,
175
+ [key]: models[relationModelName].parse(data[key]),
176
+ };
177
+ }
147
178
  return {
148
179
  ...memo,
149
180
  [key]: (
@@ -199,12 +230,13 @@ export const createModel = (baseUrl, state, collectionName, schema = {}) => {
199
230
  get relations() {
200
231
  return relations;
201
232
  },
233
+ parse,
202
234
  validateAttr: validator.validateAttr,
203
235
  validate: validator.validate,
204
236
  findMany: q => req(buildURL(null, q))
205
237
  .then(results => results.map(parse)),
206
238
  findById: (id, q) => req(buildURL(id, q))
207
- .then(raw => !!raw ? parse(raw) : raw),
239
+ .then(parse),
208
240
  create,
209
241
  update: put,
210
242
  upsert: opts => (
@@ -213,27 +245,30 @@ export const createModel = (baseUrl, state, collectionName, schema = {}) => {
213
245
  : put({ where: opts.where, data: opts.update })
214
246
  ),
215
247
  delete: id => req(buildURL(id), { method: 'DELETE' }),
248
+ stats: () => req(buildURL('_stats')),
216
249
  };
217
250
  };
218
251
 
252
+
219
253
  export const createModels = (url, state, schema) => {
220
254
  return Object.keys(schema.properties).reduce(
221
255
  (prev, key) => {
222
256
  const name = schema.properties[key].$ref.split('/').pop();
223
- return {
224
- ...prev,
257
+ return Object.assign(prev, {
225
258
  [key]: createModel(
226
259
  url,
227
260
  state,
228
261
  schema.definitions[name].plural || `${key}s`,
229
262
  schema.definitions[name],
263
+ prev,
230
264
  ),
231
- };
265
+ });
232
266
  },
233
267
  {},
234
268
  );
235
269
  };
236
270
 
271
+
237
272
  export const extendSchemaDefinitions = (schema, extended) => {
238
273
  return Object.keys(schema.definitions).reduce(
239
274
  (memo, key) => ({
@@ -259,4 +294,4 @@ export const extendSchemaDefinitions = (schema, extended) => {
259
294
  }),
260
295
  {},
261
296
  );
262
- };
297
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@laboratoria/sdk-js",
3
- "version": "1.2.0",
3
+ "version": "1.5.0",
4
4
  "description": "Laboratoria JavaScript (browser) SDK",
5
5
  "scripts": {
6
6
  "test": "jest --verbose --coverage",
@@ -9,24 +9,24 @@
9
9
  "license": "MIT",
10
10
  "dependencies": {
11
11
  "blueimp-md5": "^2.19.0",
12
- "firebase": "^9.6.5"
12
+ "firebase": "^9.6.8"
13
13
  },
14
14
  "devDependencies": {
15
- "@babel/core": "^7.17.0",
15
+ "@babel/core": "^7.17.5",
16
16
  "@babel/plugin-transform-modules-commonjs": "^7.16.8",
17
- "babel-jest": "^27.4.6",
18
- "jest": "^27.4.7",
19
- "webpack": "^5.68.0",
17
+ "babel-jest": "^27.5.1",
18
+ "jest": "^27.5.1",
19
+ "webpack": "^5.70.0",
20
20
  "webpack-cli": "^4.9.2"
21
21
  },
22
22
  "jest": {
23
23
  "testEnvironment": "jsdom",
24
24
  "coverageThreshold": {
25
25
  "global": {
26
- "statements": 97,
27
- "branches": 92,
26
+ "statements": 96.9,
27
+ "branches": 94,
28
28
  "functions": 98,
29
- "lines": 97
29
+ "lines": 96.7
30
30
  }
31
31
  }
32
32
  }
package/schemas/core.json CHANGED
@@ -123,6 +123,12 @@
123
123
  "$ref": "#/definitions/Contract"
124
124
  }
125
125
  },
126
+ "contractsAsCheckPilot": {
127
+ "type": "array",
128
+ "items": {
129
+ "$ref": "#/definitions/Contract"
130
+ }
131
+ },
126
132
  "gigs": {
127
133
  "type": "array",
128
134
  "items": {
@@ -485,30 +491,40 @@
485
491
  "isEmployment": {
486
492
  "type": "boolean"
487
493
  },
488
- "currency": {
489
- "type": "string",
490
- "enum": [
491
- "BRL",
492
- "CLP",
493
- "COP",
494
- "MXN",
495
- "PEN",
496
- "USD"
497
- ]
494
+ "feeAmount": {
495
+ "type": "integer"
498
496
  },
499
- "feeBasis": {
500
- "type": "string",
497
+ "isTrial": {
498
+ "type": "boolean",
499
+ "default": false
500
+ },
501
+ "source": {
502
+ "type": [
503
+ "string",
504
+ "null"
505
+ ],
501
506
  "enum": [
502
- "HOURLY",
503
- "MONTHLY"
507
+ "graduate",
508
+ "referral",
509
+ "jazzhr",
510
+ "web",
511
+ "linkedin",
512
+ "other"
504
513
  ]
505
514
  },
506
- "feeAmount": {
507
- "type": "integer"
508
- },
509
515
  "user": {
510
516
  "$ref": "#/definitions/User"
511
517
  },
518
+ "checkPilot": {
519
+ "anyOf": [
520
+ {
521
+ "$ref": "#/definitions/User"
522
+ },
523
+ {
524
+ "type": "null"
525
+ }
526
+ ]
527
+ },
512
528
  "country": {
513
529
  "$ref": "#/definitions/Country"
514
530
  },