@laboratoria/sdk-js 1.1.0 → 1.2.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/lib/core.js CHANGED
@@ -4,7 +4,9 @@ import schema from '../schemas/core.json';
4
4
 
5
5
  const extended = {
6
6
  Country: {
7
+ primaryKey: 'code',
7
8
  plural: 'countries',
9
+ searchProps: ['code', 'name'],
8
10
  },
9
11
  User: {
10
12
  primaryKey: 'uid',
@@ -120,7 +122,7 @@ const extended = {
120
122
  Contract: {
121
123
  inputProps: [
122
124
  'user',
123
- 'countryCode',
125
+ 'country',
124
126
  'currency',
125
127
  'isEmployment',
126
128
  'feeBasis',
@@ -129,17 +131,14 @@ const extended = {
129
131
  'start',
130
132
  'end',
131
133
  ],
132
- properties: {
133
- countryCode: {
134
- enum: ['BR', 'CL', 'CO', 'MX', 'PE'],
135
- },
136
- },
134
+ searchProps: ['user.firstName'],
135
+ getOptionLabel: ({ id, user }) => `${user?.firstName} (id: ${id})`,
137
136
  },
138
137
  Gig: {
139
138
  inputProps: [
140
- // 'contract',
141
139
  'cohort',
142
140
  'user',
141
+ 'contract',
143
142
  'role',
144
143
  'hoursPerWeek',
145
144
  'start',
package/lib/model.js CHANGED
@@ -105,7 +105,7 @@ const createBuildURL = collectionName => (id, q) => {
105
105
 
106
106
  const serializeData = (data, schema) => {
107
107
  const hasInputProps = Array.isArray(schema.inputProps);
108
- const payload = Object.keys(data).reduce(
108
+ return Object.keys(data).reduce(
109
109
  (memo, key) => {
110
110
  if (hasInputProps && !schema.inputProps.includes(key)) {
111
111
  return memo;
@@ -120,14 +120,6 @@ const serializeData = (data, schema) => {
120
120
  },
121
121
  {},
122
122
  );
123
-
124
- // {
125
- // signupCohort: {
126
- // connect: { id: signupCohort.id },
127
- // },
128
- // }
129
-
130
- return payload;
131
123
  };
132
124
 
133
125
 
@@ -136,15 +128,17 @@ export const createModel = (baseUrl, state, collectionName, schema = {}) => {
136
128
  const validator = createValidator(schema);
137
129
  const buildURL = createBuildURL(collectionName);
138
130
  const req = (...args) => createClient(baseUrl, state.authUser)(...args);
139
- const create = q => req(buildURL(), {
131
+ const create = ({ data, ...q }) => req(buildURL(null, q), {
140
132
  method: 'POST',
141
- body: Object.assign(q, { data: serializeData(q.data, schema) }),
142
- });
143
-
144
- const put = q => req(buildURL(q.where[primaryKey]), {
145
- method: 'PUT',
146
- body: Object.assign(q, { data: serializeData(q.data, schema) }),
133
+ body: serializeData(data, schema),
147
134
  });
135
+ const put = ({ data, ...q }) => {
136
+ const { where, ...rest } = q;
137
+ return req(buildURL(where[primaryKey], rest), {
138
+ method: 'PUT',
139
+ body: serializeData(data, schema),
140
+ });
141
+ };
148
142
 
149
143
  const parse = data => {
150
144
  const parsed = Object.keys(data).reduce(
@@ -200,7 +194,7 @@ export const createModel = (baseUrl, state, collectionName, schema = {}) => {
200
194
 
201
195
  return {
202
196
  get schema() {
203
- return schema;
197
+ return { ...schema, primaryKey };
204
198
  },
205
199
  get relations() {
206
200
  return relations;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@laboratoria/sdk-js",
3
- "version": "1.1.0",
3
+ "version": "1.2.0",
4
4
  "description": "Laboratoria JavaScript (browser) SDK",
5
5
  "scripts": {
6
6
  "test": "jest --verbose --coverage",
@@ -12,7 +12,7 @@
12
12
  "firebase": "^9.6.5"
13
13
  },
14
14
  "devDependencies": {
15
- "@babel/core": "^7.16.12",
15
+ "@babel/core": "^7.17.0",
16
16
  "@babel/plugin-transform-modules-commonjs": "^7.16.8",
17
17
  "babel-jest": "^27.4.6",
18
18
  "jest": "^27.4.7",