alchemy 0.0.7 → 0.1.1

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.
Files changed (105) hide show
  1. package/package.json +23 -22
  2. package/src/alchemize.ts +151 -0
  3. package/src/apply.ts +117 -0
  4. package/src/components/agent/agent.ts +45 -0
  5. package/src/components/agent/anthropic.ts +27 -0
  6. package/src/components/agent/index.ts +4 -0
  7. package/src/components/agent/model.ts +22 -0
  8. package/src/components/agent/openai.ts +44 -0
  9. package/src/components/agent/package.ts +126 -0
  10. package/src/components/agent/requirements.ts +111 -0
  11. package/src/components/agent/scrape.ts +47 -0
  12. package/src/components/agent/tsconfig.ts +150 -0
  13. package/src/components/agent/typescript.ts +177 -0
  14. package/src/components/aws/bucket.ts +168 -0
  15. package/src/components/aws/function.ts +302 -0
  16. package/src/components/aws/index.ts +6 -0
  17. package/src/components/aws/policy.ts +245 -0
  18. package/src/components/aws/queue.ts +222 -0
  19. package/src/components/aws/role.ts +245 -0
  20. package/src/components/aws/table.ts +172 -0
  21. package/src/components/esbuild.ts +128 -0
  22. package/src/components/fs.ts +45 -0
  23. package/src/destroy.ts +63 -0
  24. package/src/error.ts +16 -0
  25. package/src/global.ts +72 -0
  26. package/src/index.ts +6 -0
  27. package/src/input.ts +16 -0
  28. package/src/main.ts +34 -0
  29. package/src/output.ts +49 -0
  30. package/src/resource.ts +313 -0
  31. package/src/state.ts +100 -0
  32. package/test/aws/function.test.ts +144 -0
  33. package/test/aws/queue.test.ts +85 -0
  34. package/test/aws/role.test.ts +153 -0
  35. package/test/aws/table.test.ts +73 -0
  36. package/test/esbuild.test.ts +41 -0
  37. package/test/handler.ts +9 -0
  38. package/tsconfig.json +7 -0
  39. package/Column.js +0 -1
  40. package/Create.js +0 -1
  41. package/Delete.js +0 -1
  42. package/Drop.js +0 -1
  43. package/Insert.js +0 -1
  44. package/Makefile +0 -8
  45. package/README.md +0 -0
  46. package/Select.js +0 -1
  47. package/Table.js +0 -1
  48. package/Transaction.js +0 -1
  49. package/Types.js +0 -1
  50. package/Update.js +0 -1
  51. package/alchemy.js +0 -57
  52. package/alchemy.sublime-project +0 -9
  53. package/alchemy.sublime-workspace +0 -2304
  54. package/config/app.js +0 -8
  55. package/config/db.js +0 -20
  56. package/copy.js +0 -1
  57. package/defaultEngine.js +0 -8
  58. package/engine.js +0 -282
  59. package/getInstantiatorFunction.js +0 -28
  60. package/index.js +0 -52
  61. package/jstest.js +0 -3
  62. package/loggerFactory.js +0 -27
  63. package/logs/alchemy.log +0 -46
  64. package/logs/sql.log +0 -41
  65. package/sql/Column.js +0 -158
  66. package/sql/Columnable.js +0 -21
  67. package/sql/Create.js +0 -15
  68. package/sql/Delete.js +0 -34
  69. package/sql/Drop.js +0 -36
  70. package/sql/Insert.js +0 -96
  71. package/sql/SchemaElement.js +0 -11
  72. package/sql/Select.js +0 -192
  73. package/sql/SqlBase.js +0 -134
  74. package/sql/SqlStatement.js +0 -80
  75. package/sql/Table.js +0 -96
  76. package/sql/Transaction.js +0 -45
  77. package/sql/Update.js +0 -105
  78. package/sql/defineElement.js +0 -26
  79. package/sql/defineStatement.js +0 -26
  80. package/sql/types/BaseType.js +0 -43
  81. package/sql/types/BigSerialType.js +0 -5
  82. package/sql/types/IntegerType.js +0 -5
  83. package/sql/types/JsonType.js +0 -5
  84. package/sql/types/SerialType.js +0 -5
  85. package/sql/types/StringType.js +0 -31
  86. package/sql/types/TimestampType.js +0 -5
  87. package/sql/types/UUIDType.js +0 -5
  88. package/sql/types/defineType.js +0 -25
  89. package/sql/types/getType.js +0 -12
  90. package/sql/types/index.js +0 -11
  91. package/sql/where.js +0 -31
  92. package/sql/whereToString.js +0 -29
  93. package/test/ColumnTests.js +0 -80
  94. package/test/CreateTable.js +0 -54
  95. package/test/DeleteTests.js +0 -28
  96. package/test/DropTests.js +0 -23
  97. package/test/GetTypeTests.js +0 -56
  98. package/test/InsertTests.js +0 -86
  99. package/test/SelectExistsTests.js +0 -26
  100. package/test/SelectTests.js +0 -130
  101. package/test/TableTests.js +0 -46
  102. package/test.js +0 -8
  103. package/test.ls +0 -4
  104. package/validate.js +0 -26
  105. package/x.js +0 -5
@@ -1,80 +0,0 @@
1
- 'use strict'
2
-
3
- var jsesc = require('jsesc')
4
- var classy = require('classy')
5
- var Promise = require('bluebird')
6
- var getEngine = require('../defaultEngine')
7
-
8
-
9
- var SqlStatement = classy.define({
10
-
11
- extend: require('./SqlBase'),
12
- alias : 'sql.Statement',
13
-
14
- stateProperties: [
15
- 'name',
16
- 'parameterized'
17
- ],
18
-
19
- parameterized: true,
20
-
21
- initState: function(){
22
- this.callSuper()
23
- this.state.name = this.name
24
- },
25
-
26
- isParameterized: function(){
27
- return !!this.parameterized
28
- },
29
-
30
- isPrepared: function(){
31
- return this.isParameterized() && this.name
32
- },
33
-
34
- getParams: function(){
35
- return []
36
- },
37
-
38
- valueToSql: function(str){
39
- var result = str
40
-
41
- if (this && this.isParameterized && !this.isParameterized() && typeof str == 'string'){
42
- result = "'" + jsesc(str) + "'"
43
- }
44
-
45
- if (str instanceof SqlStatement){
46
- str = '(' + str + ')'
47
- }
48
-
49
- if (result == null){
50
- result = 'null'
51
- }
52
-
53
- return result
54
- },
55
-
56
- transact: function(){
57
- return this.execute({
58
- transaction: true
59
- })
60
- },
61
-
62
- execute: function(config){
63
-
64
- var transaction = (config && config.transaction) || this.transactional
65
-
66
- return new Promise(function(resolve, reject){
67
-
68
- var engine = getEngine()
69
- var exec = (transaction? engine.transaction: engine.query).bind(engine)
70
-
71
- exec(this, function(err, result){
72
- err?
73
- reject(err):
74
- resolve(result)
75
- })
76
- }.bind(this))
77
- }
78
- })
79
-
80
- module.exports = SqlStatement
package/sql/Table.js DELETED
@@ -1,96 +0,0 @@
1
- var classy = require('classy')
2
- var Promise = require('bluebird')
3
- var F = require('functionally')
4
-
5
- var defineElement = require('./defineElement')
6
-
7
- var Create = require('./Create')
8
- var Select = require('./Select')
9
- var Insert = require('./Insert')
10
- var Update = require('./Update')
11
- var Delete = require('./Delete')
12
-
13
- module.exports = defineElement('table', {
14
-
15
- mixins: [
16
- require('./Columnable')
17
- ],
18
-
19
- statics: {
20
- fromState: function(state){
21
- var Column = require('./Column')
22
- var columns = state.columns.map(Column.fromState)
23
-
24
- new this(state.name, null, columns)
25
- }
26
- },
27
-
28
- appendStateProperties: function(props){
29
- props.push('metadata')
30
- },
31
-
32
- init: function(name, metadata, columns){
33
-
34
- this.callSuper()
35
-
36
- this.c = {}
37
-
38
- this.name = this.validate(name || '')
39
- if (this.name == 'user'){
40
- this.name = '"user"'
41
- }
42
-
43
- this.prepareColumns.apply(this, [].slice.call(arguments, 2))
44
- this.metadata = metadata
45
-
46
- },
47
-
48
- prepareColumns: function(){
49
- this.columns.forEach(function(col){
50
- col.setTable(this)
51
- this.c[col.name] = col
52
- }, this)
53
- },
54
-
55
- toString: function(){
56
- return this.createToString()
57
- },
58
-
59
- createToString: function () {
60
- var cmd = 'CREATE TABLE IF NOT EXISTS ' + this.name + ' ('
61
-
62
- cmd += (this.columns || []).map(function(c){
63
- return c.asCreate()
64
- }).join(', ')
65
-
66
- return cmd + ');'
67
- },
68
-
69
- create: function(){
70
- return Create(this)
71
- },
72
-
73
- select: function(){
74
- var columns
75
-
76
- if (!arguments.length){
77
- columns = (columns || []).slice()
78
- } else {
79
- columns = [].slice.call(arguments, 0)
80
- }
81
-
82
- return Select(columns).from(this)
83
- },
84
-
85
- delete: function(){
86
- return Delete(this)
87
- },
88
-
89
- insert: function(){
90
- return Insert(this.columns.slice())
91
- },
92
-
93
- update: function(){
94
- return Update(this.columns.slice())
95
- }
96
- })
@@ -1,45 +0,0 @@
1
- 'use strict'
2
-
3
- var Promise = require('bluebird')
4
- var classy = require('classy')
5
- var getEngine = require('../defaultEngine')
6
-
7
- module.exports = classy.define({
8
-
9
- extend: require('./SqlStatement'),
10
- alias : 'sql.Transaction',
11
-
12
- init: function(){
13
- this.statements = [].slice.call(arguments, 0)
14
- },
15
-
16
- add: function(){
17
- this.statements = this.statements.concat([].slice.call(arguments, 0))
18
- },
19
-
20
- toString: function(){
21
- return this.valueOf()
22
- },
23
-
24
- valueOf: function(config){
25
- return 'BEGIN; ' + this.statements.map(function(s){ return s.valueOf() })
26
- },
27
-
28
- execute: function(config){
29
-
30
- var statements = this.statements.filter(function(s){
31
- return !!s
32
- })
33
-
34
- return new Promise(function(resolve, reject){
35
-
36
- getEngine()
37
- .transaction(statements, function(err, results){
38
- err?
39
- reject(err):
40
- resolve(results)
41
- })
42
-
43
- }.bind(this))
44
- }
45
- })
package/sql/Update.js DELETED
@@ -1,105 +0,0 @@
1
- var jsesc = require('jsesc')
2
-
3
- module.exports = require('./defineStatement')('udate', {
4
-
5
- extend: 'insert',
6
-
7
- toString: function(){
8
- var target = this.targetToString()
9
- var cols = this.columnsToString()
10
- var values = this.valuesToString()
11
-
12
- return 'UPDATE ' + target + ' SET ' + cols + ' VALUES ' + values + ';'
13
- },
14
-
15
- getInsertColumns: function(){
16
- var cols = []
17
-
18
- this.values.forEach(function(values){
19
- Object.keys(values).forEach(function(k){
20
- if (!~cols.indexOf(k)){
21
- cols.push(k)
22
- }
23
- })
24
- })
25
-
26
- return cols
27
- },
28
-
29
- valuesToString: function(){
30
- var cols = this.getInsertColumns()
31
-
32
- return this.values.map(function(values){
33
-
34
- var result = cols.map(function(colName){
35
- return this.valueToString(values[colName])
36
- }, this)
37
-
38
- return '(' + result.join(', ') + ')'
39
- }, this).join(', ')
40
- },
41
-
42
- columnsToString: function(){
43
- return '(' + this.getInsertColumns().join(', ') + ')'
44
- },
45
-
46
- valueToString: function(str){
47
- var result = str
48
-
49
- if (typeof str == 'string'){
50
- result = "'" + jsesc(str) + "'"
51
- }
52
-
53
- if (result == null){
54
- result = 'null'
55
- }
56
-
57
- return result
58
- },
59
-
60
- intoToString: function() {
61
- var into = this.intoTarget
62
-
63
- if (!into){
64
- this.columns.some(function(c){
65
- if (c.table.name){
66
- into = c.table.name
67
- return true
68
- }
69
- })
70
- }
71
-
72
- return into
73
- },
74
-
75
- values: function(values){
76
- this.values = Array.isArray(values)?
77
- values:
78
- [values]
79
-
80
- var cols = {}
81
- this.columns.forEach(function(col){
82
- cols[col.name] = 1
83
- })
84
-
85
- this.values = this.values.map(function(values){
86
- var validValues = {}
87
- var count = 0
88
-
89
- Object.keys(values).forEach(function(k){
90
- if (k in cols){
91
- validValues[k] = values[k]
92
- count++
93
- }
94
- })
95
-
96
- return count? validValues: null
97
- })
98
-
99
- this.values = this.values.filter(function(v){
100
- return !!v
101
- })
102
-
103
- return this
104
- }
105
- })
@@ -1,26 +0,0 @@
1
- 'use strict'
2
-
3
- var SchemaElement = require('./SchemaElement')
4
- var classy = require('classy')
5
- var toUpperFirst = require('ustring').toUpperFirst
6
-
7
- module.exports = function(type, config){
8
-
9
- if (arguments.length < 2){
10
- return console.error('Please provide a type for the SchemaElement!')
11
- }
12
-
13
- config = config || {}
14
-
15
- var extend = config.extend
16
-
17
- if (typeof extend == 'string'){
18
- extend = require('./' + toUpperFirst(extend))
19
- }
20
-
21
- config.extend = extend || SchemaElement
22
- config.alias = config.alias || 'schema.' + toUpperFirst(type)
23
- config.schemaType = type
24
-
25
- return classy.define(config)
26
- }
@@ -1,26 +0,0 @@
1
- 'use strict'
2
-
3
- var SqlStatement = require('./SqlStatement')
4
- var classy = require('classy')
5
- var toUpperFirst = require('ustring').toUpperFirst
6
-
7
- module.exports = function(name, config){
8
-
9
- if (arguments.length < 2){
10
- return console.error('Please provide a name for the SqlStatement!')
11
- }
12
-
13
- config = config || {}
14
-
15
- var extend = config.extend
16
-
17
- if (typeof extend == 'string'){
18
- extend = require('./' + toUpperFirst(extend))
19
- }
20
-
21
- config.extend = extend || SqlStatement
22
- config.alias = config.alias || 'sql.' + toUpperFirst(name)
23
- config.name = name
24
-
25
- return classy.define(config)
26
- }
@@ -1,43 +0,0 @@
1
- 'use strict'
2
-
3
- var classy = require('classy')
4
-
5
- var Type = classy.define({
6
-
7
- alias : 'sql.BaseType',
8
- extend: require('../SqlBase'),
9
-
10
- statics: {
11
-
12
- fromState: function(state){
13
- var result = new this()
14
-
15
- result.copy(state)
16
-
17
- return result
18
- },
19
-
20
- toString: function(){
21
- return this.prototype.type
22
- },
23
-
24
- toJSON: function(){
25
- return {
26
- type: this.toString()
27
- }
28
- }
29
- },
30
-
31
- toString: function(){
32
- return this.type
33
- },
34
-
35
- toJSON: function(){
36
- return {
37
- type : this.type,
38
- value: this.toString()
39
- }
40
- }
41
- })
42
-
43
- module.exports = Type
@@ -1,5 +0,0 @@
1
- 'use strict'
2
-
3
- module.exports = require('./defineType')({
4
- type: 'bigserial'
5
- })
@@ -1,5 +0,0 @@
1
- var defineType = require('./defineType')
2
-
3
- module.exports = defineType({
4
- type: 'integer'
5
- })
@@ -1,5 +0,0 @@
1
- var defineType = require('./defineType')
2
-
3
- module.exports = defineType({
4
- type: 'json'
5
- })
@@ -1,5 +0,0 @@
1
- var defineType = require('./defineType')
2
-
3
- module.exports = defineType({
4
- type: 'serial'
5
- })
@@ -1,31 +0,0 @@
1
- var defineType = require('./defineType')
2
-
3
- module.exports = defineType({
4
-
5
- type: 'string',
6
-
7
- statics: {
8
- displayName: 'StringType',
9
- defaultLength: 50,
10
- toString: function(){
11
- return 'varchar(' + StringType.defaultLength + ')'
12
- }
13
- },
14
-
15
- init: function(len){
16
- this.len = len
17
- },
18
-
19
- toString: function(){
20
- return 'varchar(' + this.len + ')'
21
- },
22
-
23
- toJSON: function(){
24
- var json = this.callSuper()
25
-
26
- json.len = this.len
27
-
28
- return json
29
- }
30
-
31
- })
@@ -1,5 +0,0 @@
1
- var defineType = require('./defineType')
2
-
3
- module.exports = defineType({
4
- type: 'timestamp'
5
- })
@@ -1,5 +0,0 @@
1
- var defineType = require('./defineType')
2
-
3
- module.exports = defineType({
4
- type: 'uuid'
5
- })
@@ -1,25 +0,0 @@
1
- 'use strict'
2
-
3
- var classy = require('classy')
4
- var toUpperFirst = require('ustring').toUpperFirst
5
- var Type = require('./BaseType')
6
-
7
- function define(config){
8
- config = config || {}
9
-
10
- config.extend = config.extend || Type
11
- config.alias = 'sql.' + toUpperFirst(config.type)
12
-
13
- var NewType = classy.define(config)
14
-
15
- if (!config.statics || !config.statics.toString){
16
- NewType.toString = NewType.$superClass.toString
17
- }
18
- if (!config.statics || !config.statics.toJSON){
19
- NewType.toJSON = NewType.$superClass.toJSON
20
- }
21
-
22
- return NewType
23
- }
24
-
25
- module.exports = define
@@ -1,12 +0,0 @@
1
- var toUpperFirst = require('ustring').toUpperFirst
2
- var F = require('functionally')
3
- var find = F.find
4
- var types = require('./index')
5
-
6
- var equals = F.curry(function(t, type){
7
- return t === type.prototype.type
8
- })
9
-
10
- module.exports = function(json){
11
- return find(equals(json.type), types)
12
- }
@@ -1,11 +0,0 @@
1
- //just add new types here as you need them
2
-
3
- module.exports = {
4
- String : require('./StringType'),
5
- Integer : require('./IntegerType'),
6
- Serial : require('./SerialType'), //serial integer up to 2^31
7
- BigSerial: require('./BigSerialType'), //serial big integer
8
- Json : require('./JsonType'),
9
- UUID : require('./UUIDType'),
10
- Timestamp: require('./TimestampType')
11
- }
package/sql/where.js DELETED
@@ -1,31 +0,0 @@
1
- var F = require('functionally')
2
-
3
- module.exports = function(column){
4
- var self = this
5
- this.whereConditions = this.whereConditions || []
6
-
7
- var thisWhere = this.where.bind(this)
8
- var thisToString = this.toString.bind(this)
9
-
10
- var all = this.whereConditions
11
-
12
- var push = F.curry(function(operator, value, options){
13
- all.push([column, operator, value, options || {} ])
14
-
15
- return {
16
- and: thisWhere,
17
- toString: thisToString,
18
- end: function(){
19
- return self
20
- }
21
- }
22
- }, 2)
23
-
24
- return {
25
- equals: push('='),
26
- is: push('='),
27
- lt: push('<'),
28
- gt: push('>'),
29
- in: push(' in ')
30
- }
31
- }
@@ -1,29 +0,0 @@
1
- module.exports = function(config) {
2
- config = config || {}
3
-
4
- var parameterized = config.parameterized === undefined?
5
- this.parameterized:
6
- config.parameterized
7
- var where = ''
8
-
9
- if (this.whereConditions && this.whereConditions.length){
10
- where = this.whereConditions.map(function(cond, i){
11
- var col = cond[0]
12
- var colName = typeof col == 'string'? col: col.name
13
- var operator = cond[1]
14
- var value = cond[2]
15
-
16
- var result = colName + ' ' + operator + ' '
17
- var type = cond[3].type
18
- var options = type? '::' + type: ''
19
-
20
- return parameterized?
21
- result + '$' + (i + 1) + options:
22
- result + this.valueToSql(value) + options
23
- }, this).join(' AND ')
24
-
25
- where = ' WHERE ' + where
26
- }
27
-
28
- return where
29
- }
@@ -1,80 +0,0 @@
1
- var Column = require('../Column')
2
- var Types = require('../Types')
3
-
4
- describe('Column', function(){
5
-
6
- it('should have name set', function(){
7
- var col = Column('firstName', Types.String)
8
-
9
- col.name
10
- .should.equal('firstName')
11
-
12
- col.state.name
13
- .should
14
- .equal(col.name)
15
-
16
- col.state.name
17
- .should.equal('firstName')
18
-
19
- })
20
-
21
- it('should return state correctly', function(){
22
- var col = Column('firstName', Types.String(35), { primaryKey: true})
23
-
24
- var state = col.toState()
25
-
26
- state.type.type
27
- .should
28
- .equal('string')
29
-
30
- state.type.value
31
- .should
32
- .equal('varchar(35)')
33
-
34
- state.name
35
- .should
36
- .equal('firstName')
37
-
38
- state.options.primaryKey
39
- .should
40
- .equal(true)
41
- })
42
-
43
- it('should return valid column from fromState', function(){
44
- var col1 = Column('lastName', Types.String(35), { primaryKey: true})
45
-
46
- var col2 = Column.fromState(col1.toState())
47
-
48
- JSON.stringify(col1.toState())
49
- .should
50
- .equal(
51
- JSON.stringify(col2.toState())
52
- )
53
- })
54
-
55
- it('should validate type correctly', function(){
56
- Column('name', Types.String)
57
- .isValidType()
58
- .should.equal(true)
59
-
60
- new Column('name', Types.String)
61
- .isValidType()
62
- .should.equal(true)
63
-
64
- Column('name', Types.String(50))
65
- .isValidType()
66
- .should.equal(true)
67
-
68
- Column('name', Types.XXX)
69
- .isValidType()
70
- .should.equal(false)
71
- })
72
-
73
- it('should be instantiated correctly', function(){
74
- var bool = Column('name') instanceof Column
75
- bool.should.equal(true)
76
-
77
- bool = new Column('name') instanceof Column
78
- bool.should.equal(true)
79
- })
80
- })