Skip to content

Commit 6f78e1c

Browse files
author
leancloud-bot
committed
chore(build): build 1fcc28d [skip ci]
1 parent 1fcc28d commit 6f78e1c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

68 files changed

+225460
-0
lines changed

dist/av-core-min.js

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/av-core-min.js.map

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/av-core.js

Lines changed: 25189 additions & 0 deletions
Large diffs are not rendered by default.

dist/av-core.js.map

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/av-live-query-core-min.js

Lines changed: 25 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/av-live-query-core-min.js.map

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/av-live-query-core.js

Lines changed: 41960 additions & 0 deletions
Large diffs are not rendered by default.

dist/av-live-query-core.js.map

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/av-live-query-min.js

Lines changed: 39 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/av-live-query-min.js.map

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/av-live-query-weapp-min.js

Lines changed: 25 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/av-live-query-weapp-min.js.map

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/av-live-query-weapp.js

Lines changed: 43553 additions & 0 deletions
Large diffs are not rendered by default.

dist/av-live-query-weapp.js.map

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/av-live-query.js

Lines changed: 45409 additions & 0 deletions
Large diffs are not rendered by default.

dist/av-live-query.js.map

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/av-min.js

Lines changed: 22 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/av-min.js.map

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/av-weapp-min.js

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/av-weapp-min.js.map

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/av-weapp.js

Lines changed: 27610 additions & 0 deletions
Large diffs are not rendered by default.

dist/av-weapp.js.map

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/av.js

Lines changed: 28823 additions & 0 deletions
Large diffs are not rendered by default.

dist/av.js.map

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/node/acl.js

Lines changed: 294 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,294 @@
1+
"use strict";
2+
3+
var _ = require('underscore');
4+
5+
module.exports = function (AV) {
6+
var PUBLIC_KEY = '*';
7+
/**
8+
* Creates a new ACL.
9+
* If no argument is given, the ACL has no permissions for anyone.
10+
* If the argument is a AV.User, the ACL will have read and write
11+
* permission for only that user.
12+
* If the argument is any other JSON object, that object will be interpretted
13+
* as a serialized ACL created with toJSON().
14+
* @see AV.Object#setACL
15+
* @class
16+
*
17+
* <p>An ACL, or Access Control List can be added to any
18+
* <code>AV.Object</code> to restrict access to only a subset of users
19+
* of your application.</p>
20+
*/
21+
22+
AV.ACL = function (arg1) {
23+
var self = this;
24+
self.permissionsById = {};
25+
26+
if (_.isObject(arg1)) {
27+
if (arg1 instanceof AV.User) {
28+
self.setReadAccess(arg1, true);
29+
self.setWriteAccess(arg1, true);
30+
} else {
31+
if (_.isFunction(arg1)) {
32+
throw new Error('AV.ACL() called with a function. Did you forget ()?');
33+
}
34+
35+
AV._objectEach(arg1, function (accessList, userId) {
36+
if (!_.isString(userId)) {
37+
throw new Error('Tried to create an ACL with an invalid userId.');
38+
}
39+
40+
self.permissionsById[userId] = {};
41+
42+
AV._objectEach(accessList, function (allowed, permission) {
43+
if (permission !== 'read' && permission !== 'write') {
44+
throw new Error('Tried to create an ACL with an invalid permission type.');
45+
}
46+
47+
if (!_.isBoolean(allowed)) {
48+
throw new Error('Tried to create an ACL with an invalid permission value.');
49+
}
50+
51+
self.permissionsById[userId][permission] = allowed;
52+
});
53+
});
54+
}
55+
}
56+
};
57+
/**
58+
* Returns a JSON-encoded version of the ACL.
59+
* @return {Object}
60+
*/
61+
62+
63+
AV.ACL.prototype.toJSON = function () {
64+
return _.clone(this.permissionsById);
65+
};
66+
67+
AV.ACL.prototype._setAccess = function (accessType, userId, allowed) {
68+
if (userId instanceof AV.User) {
69+
userId = userId.id;
70+
} else if (userId instanceof AV.Role) {
71+
userId = 'role:' + userId.getName();
72+
}
73+
74+
if (!_.isString(userId)) {
75+
throw new Error('userId must be a string.');
76+
}
77+
78+
if (!_.isBoolean(allowed)) {
79+
throw new Error('allowed must be either true or false.');
80+
}
81+
82+
var permissions = this.permissionsById[userId];
83+
84+
if (!permissions) {
85+
if (!allowed) {
86+
// The user already doesn't have this permission, so no action needed.
87+
return;
88+
} else {
89+
permissions = {};
90+
this.permissionsById[userId] = permissions;
91+
}
92+
}
93+
94+
if (allowed) {
95+
this.permissionsById[userId][accessType] = true;
96+
} else {
97+
delete permissions[accessType];
98+
99+
if (_.isEmpty(permissions)) {
100+
delete this.permissionsById[userId];
101+
}
102+
}
103+
};
104+
105+
AV.ACL.prototype._getAccess = function (accessType, userId) {
106+
if (userId instanceof AV.User) {
107+
userId = userId.id;
108+
} else if (userId instanceof AV.Role) {
109+
userId = 'role:' + userId.getName();
110+
}
111+
112+
var permissions = this.permissionsById[userId];
113+
114+
if (!permissions) {
115+
return false;
116+
}
117+
118+
return permissions[accessType] ? true : false;
119+
};
120+
/**
121+
* Set whether the given user is allowed to read this object.
122+
* @param userId An instance of AV.User or its objectId.
123+
* @param {Boolean} allowed Whether that user should have read access.
124+
*/
125+
126+
127+
AV.ACL.prototype.setReadAccess = function (userId, allowed) {
128+
this._setAccess('read', userId, allowed);
129+
};
130+
/**
131+
* Get whether the given user id is *explicitly* allowed to read this object.
132+
* Even if this returns false, the user may still be able to access it if
133+
* getPublicReadAccess returns true or a role that the user belongs to has
134+
* write access.
135+
* @param userId An instance of AV.User or its objectId, or a AV.Role.
136+
* @return {Boolean}
137+
*/
138+
139+
140+
AV.ACL.prototype.getReadAccess = function (userId) {
141+
return this._getAccess('read', userId);
142+
};
143+
/**
144+
* Set whether the given user id is allowed to write this object.
145+
* @param userId An instance of AV.User or its objectId, or a AV.Role..
146+
* @param {Boolean} allowed Whether that user should have write access.
147+
*/
148+
149+
150+
AV.ACL.prototype.setWriteAccess = function (userId, allowed) {
151+
this._setAccess('write', userId, allowed);
152+
};
153+
/**
154+
* Get whether the given user id is *explicitly* allowed to write this object.
155+
* Even if this returns false, the user may still be able to write it if
156+
* getPublicWriteAccess returns true or a role that the user belongs to has
157+
* write access.
158+
* @param userId An instance of AV.User or its objectId, or a AV.Role.
159+
* @return {Boolean}
160+
*/
161+
162+
163+
AV.ACL.prototype.getWriteAccess = function (userId) {
164+
return this._getAccess('write', userId);
165+
};
166+
/**
167+
* Set whether the public is allowed to read this object.
168+
* @param {Boolean} allowed
169+
*/
170+
171+
172+
AV.ACL.prototype.setPublicReadAccess = function (allowed) {
173+
this.setReadAccess(PUBLIC_KEY, allowed);
174+
};
175+
/**
176+
* Get whether the public is allowed to read this object.
177+
* @return {Boolean}
178+
*/
179+
180+
181+
AV.ACL.prototype.getPublicReadAccess = function () {
182+
return this.getReadAccess(PUBLIC_KEY);
183+
};
184+
/**
185+
* Set whether the public is allowed to write this object.
186+
* @param {Boolean} allowed
187+
*/
188+
189+
190+
AV.ACL.prototype.setPublicWriteAccess = function (allowed) {
191+
this.setWriteAccess(PUBLIC_KEY, allowed);
192+
};
193+
/**
194+
* Get whether the public is allowed to write this object.
195+
* @return {Boolean}
196+
*/
197+
198+
199+
AV.ACL.prototype.getPublicWriteAccess = function () {
200+
return this.getWriteAccess(PUBLIC_KEY);
201+
};
202+
/**
203+
* Get whether users belonging to the given role are allowed
204+
* to read this object. Even if this returns false, the role may
205+
* still be able to write it if a parent role has read access.
206+
*
207+
* @param role The name of the role, or a AV.Role object.
208+
* @return {Boolean} true if the role has read access. false otherwise.
209+
* @throws {String} If role is neither a AV.Role nor a String.
210+
*/
211+
212+
213+
AV.ACL.prototype.getRoleReadAccess = function (role) {
214+
if (role instanceof AV.Role) {
215+
// Normalize to the String name
216+
role = role.getName();
217+
}
218+
219+
if (_.isString(role)) {
220+
return this.getReadAccess('role:' + role);
221+
}
222+
223+
throw new Error('role must be a AV.Role or a String');
224+
};
225+
/**
226+
* Get whether users belonging to the given role are allowed
227+
* to write this object. Even if this returns false, the role may
228+
* still be able to write it if a parent role has write access.
229+
*
230+
* @param role The name of the role, or a AV.Role object.
231+
* @return {Boolean} true if the role has write access. false otherwise.
232+
* @throws {String} If role is neither a AV.Role nor a String.
233+
*/
234+
235+
236+
AV.ACL.prototype.getRoleWriteAccess = function (role) {
237+
if (role instanceof AV.Role) {
238+
// Normalize to the String name
239+
role = role.getName();
240+
}
241+
242+
if (_.isString(role)) {
243+
return this.getWriteAccess('role:' + role);
244+
}
245+
246+
throw new Error('role must be a AV.Role or a String');
247+
};
248+
/**
249+
* Set whether users belonging to the given role are allowed
250+
* to read this object.
251+
*
252+
* @param role The name of the role, or a AV.Role object.
253+
* @param {Boolean} allowed Whether the given role can read this object.
254+
* @throws {String} If role is neither a AV.Role nor a String.
255+
*/
256+
257+
258+
AV.ACL.prototype.setRoleReadAccess = function (role, allowed) {
259+
if (role instanceof AV.Role) {
260+
// Normalize to the String name
261+
role = role.getName();
262+
}
263+
264+
if (_.isString(role)) {
265+
this.setReadAccess('role:' + role, allowed);
266+
return;
267+
}
268+
269+
throw new Error('role must be a AV.Role or a String');
270+
};
271+
/**
272+
* Set whether users belonging to the given role are allowed
273+
* to write this object.
274+
*
275+
* @param role The name of the role, or a AV.Role object.
276+
* @param {Boolean} allowed Whether the given role can write this object.
277+
* @throws {String} If role is neither a AV.Role nor a String.
278+
*/
279+
280+
281+
AV.ACL.prototype.setRoleWriteAccess = function (role, allowed) {
282+
if (role instanceof AV.Role) {
283+
// Normalize to the String name
284+
role = role.getName();
285+
}
286+
287+
if (_.isString(role)) {
288+
this.setWriteAccess('role:' + role, allowed);
289+
return;
290+
}
291+
292+
throw new Error('role must be a AV.Role or a String');
293+
};
294+
};

dist/node/adapter.js

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
"use strict";
2+
3+
var _interopRequireDefault = require("@babel/runtime-corejs3/helpers/interopRequireDefault");
4+
5+
var _keys = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/keys"));
6+
7+
var _ = require('underscore');
8+
9+
var EventEmitter = require('eventemitter3');
10+
11+
var _require = require('./utils'),
12+
inherits = _require.inherits;
13+
14+
var AdapterManager = inherits(EventEmitter, {
15+
constructor: function constructor() {
16+
EventEmitter.apply(this);
17+
this._adapters = {};
18+
},
19+
getAdapter: function getAdapter(name) {
20+
var adapter = this._adapters[name];
21+
22+
if (adapter === undefined) {
23+
throw new Error("".concat(name, " adapter is not configured"));
24+
}
25+
26+
return adapter;
27+
},
28+
setAdapters: function setAdapters(newAdapters) {
29+
var _this = this;
30+
31+
_.extend(this._adapters, newAdapters);
32+
33+
(0, _keys.default)(_).call(_, newAdapters).forEach(function (name) {
34+
return _this.emit(name, newAdapters[name]);
35+
});
36+
}
37+
});
38+
var adapterManager = new AdapterManager();
39+
module.exports = {
40+
getAdapter: adapterManager.getAdapter.bind(adapterManager),
41+
setAdapters: adapterManager.setAdapters.bind(adapterManager),
42+
adapterManager: adapterManager
43+
};

0 commit comments

Comments
 (0)