presidium 0.16.21 → 0.16.23

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.
@@ -67,7 +67,7 @@ jobs:
67
67
 
68
68
  strategy:
69
69
  matrix:
70
- node-version: [14.x, 15.x, 16.x, 17.x]
70
+ node-version: [15.x, 16.x, 17.x, 18.x]
71
71
 
72
72
  steps:
73
73
  - uses: actions/checkout@v2
package/DynamoIndex.js CHANGED
@@ -150,6 +150,9 @@ DynamoIndex.prototype.query = async function dynamoIndexQuery(
150
150
  }
151
151
 
152
152
  const ExpressionAttributeNames = pipe([
153
+ ...keyConditionStatements, ...filterExpressionStatements
154
+ ], [
155
+ filter(statement => statement.includes(':')),
153
156
  fork([
154
157
  map(
155
158
  statement => statement.trim().startsWith('begins_with')
@@ -169,22 +172,27 @@ DynamoIndex.prototype.query = async function dynamoIndexQuery(
169
172
  map(field => ({ [`#${hashJSON(field)}`]: field })),
170
173
  {},
171
174
  ),
172
- ])([...keyConditionStatements, ...filterExpressionStatements])
175
+ ])
173
176
 
174
177
  const ExpressionAttributeValues = map.entries(
175
178
  ([placeholder, value]) => [`:${placeholder}`, Dynamo.AttributeValue(value)],
176
179
  )(values)
177
180
 
178
- const KeyConditionExpression = keyConditionStatements.map(function (statement) {
179
- if (statement.startsWith('begins_with')) {
180
- const [field, prefix] = statement // 'begins_with(name, :prefix)'
181
- .split(/[()]/)[1] // 'name, :prefix'
182
- .split(',').map(trim) // ['name', ':prefix']
183
- return `begins_with(#${hashJSON(field)}, ${prefix})`
184
- }
185
- const [field, rest] = statement.split(/ (.+)/)
186
- return `#${hashJSON(field)} ${rest}`
187
- }).join(' AND ')
181
+ const KeyConditionExpression = keyConditionStatements
182
+ .filter(statement => statement.includes(':'))
183
+ .map(statement => {
184
+ if (statement.startsWith('begins_with')) {
185
+ const [field, prefix] = statement // 'begins_with(name, :prefix)'
186
+ .split(/[()]/)[1] // 'name, :prefix'
187
+ .split(',').map(trim) // ['name', ':prefix']
188
+ return `begins_with(#${hashJSON(field)}, ${prefix})`
189
+ }
190
+ const [field, rest] = statement.split(/ (.+)/)
191
+ return `#${hashJSON(field)} ${rest}`
192
+ })
193
+ .join(' AND ')
194
+
195
+ console.log(KeyConditionExpression)
188
196
 
189
197
  const FilterExpression = filterExpressionStatements.map(function (statement) {
190
198
  if (statement.startsWith('begins_with')) {
@@ -107,6 +107,29 @@ const test = new Test('DynamoIndex', DynamoIndex)
107
107
  ScannedCount: 2
108
108
  })
109
109
 
110
+ assert.deepEqual(
111
+ await index.query('status = :status AND createTime > 1000', {
112
+ status: 'waitlist',
113
+ }),
114
+ {
115
+ Items: [
116
+ {
117
+ createTime: { N: '1001' },
118
+ id: { S: '2' },
119
+ status: { S: 'waitlist' },
120
+ name: { S: 'geo' },
121
+ },
122
+ {
123
+ createTime: { N: '1002' },
124
+ id: { S: '3' },
125
+ status: { S: 'waitlist' },
126
+ name: { S: 'john' },
127
+ }
128
+ ],
129
+ Count: 2,
130
+ ScannedCount: 2
131
+ })
132
+
110
133
  assert.deepEqual(
111
134
  await index.query('status = :status AND createTime BETWEEN :lower AND :upper', {
112
135
  status: 'waitlist',
package/Gzip.js ADDED
@@ -0,0 +1,29 @@
1
+ const zlib = require('zlib')
2
+ const StringStream = require('./internal/StringStream')
3
+
4
+ /**
5
+ * @name Gzip
6
+ *
7
+ * @synopsis
8
+ * ```coffeescript [specscript]
9
+ * Gzip(raw string) -> gzip stream
10
+ *
11
+ * Gzip() -> gzip stream
12
+ * ```
13
+ *
14
+ * @description
15
+ * ```js
16
+ * const data = { a: 1 }
17
+ *
18
+ * Gzip(JSON.stringify(data)).pipe(response)
19
+ * ```
20
+ */
21
+
22
+ const Gzip = function (raw) {
23
+ if (raw == null) {
24
+ return zlib.createGzip()
25
+ }
26
+ return StringStream(raw).pipe(zlib.createGzip())
27
+ }
28
+
29
+ module.exports = Gzip
package/Gzip.test.js ADDED
@@ -0,0 +1,30 @@
1
+ const Test = require('thunk-test')
2
+ const assert = require('assert')
3
+ const zlib = require('zlib')
4
+ const Gzip = require('./Gzip')
5
+ const StreamString = require('./internal/StreamString')
6
+ const StringStream = require('./internal/StringStream')
7
+
8
+ const test = new Test('Gzip', async function () {
9
+ const raw = 'aaaaabbbbbbbcccc'
10
+
11
+ {
12
+ const transformed = await StreamString(
13
+ Gzip(raw).pipe(zlib.createGunzip())
14
+ )
15
+ assert.equal(raw, transformed)
16
+ }
17
+
18
+ {
19
+ const transformed = await StreamString(
20
+ StringStream(raw).pipe(Gzip()).pipe(zlib.createGunzip())
21
+ )
22
+ assert.equal(raw, transformed)
23
+ }
24
+ }).case()
25
+
26
+ if (process.argv[1] == __filename) {
27
+ test()
28
+ }
29
+
30
+ module.exports = test
@@ -0,0 +1,14 @@
1
+ // stream Readable => str string
2
+ const StreamString = function (stream) {
3
+ return new Promise(resolve => {
4
+ let str = ''
5
+ stream.on('data', chunk => {
6
+ str += chunk
7
+ })
8
+ stream.on('end', () => {
9
+ resolve(str)
10
+ })
11
+ })
12
+ }
13
+
14
+ module.exports = StreamString
@@ -0,0 +1,15 @@
1
+ const { Readable } = require('stream')
2
+
3
+ /**
4
+ * @name StringStream
5
+ *
6
+ * @synopsis
7
+ * ```coffeescript [specscript]
8
+ * StringStream(str string)
9
+ * ```
10
+ */
11
+ const StringStream = function (str) {
12
+ return Readable.from([str])
13
+ }
14
+
15
+ module.exports = StringStream
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "presidium",
3
- "version": "0.16.21",
3
+ "version": "0.16.23",
4
4
  "description": "A library for creating web services",
5
5
  "author": "Richard Tong",
6
6
  "license": "MIT",