Last active
March 1, 2023 03:41
-
-
Save wmakeev/2fdd4111eaccd62e310ea159df1da912 to your computer and use it in GitHub Desktop.
$mol samples #mol #sample
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// prettier-ignore | |
export class $my_model extends $mol_object { | |
static type() { | |
return '' | |
} | |
@$mol_mem_key | |
static item( id: string ) { | |
const model = this.create( instance => { | |
instance.id = $mol_const( $mol_data_string( id ) ) | |
} ) | |
return model | |
} | |
@$mol_mem_key | |
query<Query extends $hyoo_harp_query>( harp_query: Query ) { | |
const query_string = this.$.$hyoo_harp_to_string( harp_query ) | |
const response = $my_transport.load( query_string ) | |
} | |
} | |
// prettier-ignore | |
export class $my_document extends $mol_object { | |
@$mol_mem_key | |
static item( id: string ) { | |
const model = this.create( instance => { | |
instance.id = this.$.$mol_const( $mol_data_string( id ) ) | |
} ) | |
return model | |
} | |
@$mol_mem_key | |
query( code: string ) { | |
const harp_response = this.$.$my_document.query( { | |
code: { | |
"=": [ [ code ] ] | |
} | |
} ) | |
} | |
} | |
// prettier-ignore | |
export class $my_app extends $.$my_app { | |
@$mol_mem | |
doc_type() { | |
return 'customerorder' | |
} | |
@$mol_mem_key | |
doc( id: string ) { | |
const doc = this.$.$my_document.item( id ) | |
return doc | |
} | |
@$mol_mem_key | |
doc_by_name( name: string ) { | |
const type = this.doc_type() | |
const harp_response = this.$.$my_document.query( { | |
[ type ]: { | |
name: { | |
"=": [ [ name ] ] | |
} | |
} | |
} ) | |
const doc_ids = Object.keys( harp_response[ type ] ) | |
return harp_response[ type ][ doc_ids[ 0 ] ] | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
namespace $ { | |
export interface $texspb_model_search_params { | |
filter: Record<string, string>; | |
} | |
const HarpString = $hyoo_harp_scheme({}, String); | |
const HarpNumber = $hyoo_harp_scheme({}, Number); | |
const Position = $hyoo_harp_scheme({ | |
id: HarpString, | |
name: HarpString, | |
quantity: HarpNumber, | |
barcodes: $mol_data_array(HarpString), | |
}); | |
const Document = $hyoo_harp_scheme({ | |
id: HarpString, | |
type: HarpString, | |
name: HarpString, | |
positions: $mol_data_array(Position), | |
}); | |
export class $texspb_model extends $mol_object2 { | |
static type() { | |
return ""; | |
} | |
id() { | |
return ""; | |
} | |
@$mol_mem_key | |
static item<Model extends typeof $texspb_model>(this: Model, id: string) { | |
const model = this.create((instance) => { | |
instance.id = $mol_const($mol_data_string(id)); | |
}) as InstanceType<Model>; | |
return model; | |
} | |
@$mol_mem | |
static list<Model extends typeof $texspb_model>(this: Model) { | |
return $mol_data_array((id) => this.item(id) as InstanceType<Model>); | |
} | |
@$mol_mem_key | |
static collection<Model extends typeof $texspb_model>( | |
this: Model, | |
query: typeof Document.Value | |
) { | |
const harp_query_string = Document.build(query); | |
// ... | |
return []; | |
} | |
@$mol_mem | |
static data() { | |
const tree = $mol_tree.fromString(this.$.$mol_fetch.text(this.uri())); | |
const json = new $mol_tree({ type: "*", sub: tree.sub }).toJSON(); | |
return json; | |
} | |
@$mol_mem | |
data(next?: any) { | |
const Model = this.constructor as typeof $texspb_model; | |
return Model.data()[this.id()]; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment